aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Kölker <jason@koelker.net>2016-06-22 18:41:11 +0000
committerTollef Fog Heen <tfheen@err.no>2016-06-29 21:32:18 +0200
commit4f3e9142f4f4fbc460a3b1459c4182bce7c50734 (patch)
treef9909e8ae6ab7e255a5c0be152b44363a6cd4932
parentcc90a4f0368b54930544ababdb324e4a49cfb254 (diff)
downloadwee-slack-4f3e9142f4f4fbc460a3b1459c4182bce7c50734.tar.gz
Sets are not JSON serializable
Commit 46384b6782f0b73318f764bf02f24cdbcdd059c9 introduced storing the reaction users as a set in the message_json representation. However sets are not JSON serializable. Instead uses a list and checks for membership prior to manipulation. Fixes the traceback: Traceback (most recent call last): File "wee_slack.py", line 2105, in cache_write_cb cache_file.write("{}\n".format(json.dumps(message.message_json))) File "/usr/lib/python2.7/json/__init__.py", line 244, in dumps return _default_encoder.encode(obj) File "/usr/lib/python2.7/json/encoder.py", line 207, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode return _iterencode(o, 0) File "/usr/lib/python2.7/json/encoder.py", line 184, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: set([u'Uxxxxxxxx']) is not JSON serializable
-rw-r--r--wee_slack.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py
index cbe98ec..5098748 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -952,18 +952,19 @@ class Message(object):
if "reactions" in self.message_json:
found = False
for r in self.message_json["reactions"]:
- if r["name"] == reaction:
- r["users"].add(user)
+ if r["name"] == reaction and user not in r["users"]:
+ r["users"].append(user)
found = True
+
if not found:
- self.message_json["reactions"].append({u"name": reaction, u"users": {user}})
+ self.message_json["reactions"].append({u"name": reaction, u"users": [user]})
else:
- self.message_json["reactions"] = [{u"name": reaction, u"users": {user}}]
+ self.message_json["reactions"] = [{u"name": reaction, u"users": [user]}]
def remove_reaction(self, reaction, user):
if "reactions" in self.message_json:
for r in self.message_json["reactions"]:
- if r["name"] == reaction:
+ if r["name"] == reaction and user in r["users"]:
r["users"].remove(user)
else:
pass