Fetch all unread messages from slack, along with user names

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-05-26 11:39:08 -04:00
parent 9065d67acb
commit a6ccb45f83
1 changed files with 13 additions and 6 deletions

View File

@ -20,9 +20,7 @@ def call_method(method, args = dict()):
server = "https://slack.com/api/"
with request.urlopen("%s/%s?%s" % (server, method, argstr)) as f:
text = f.read().decode()
text = text.replace("\\u2014", " - ")
return json.loads(text)
return json.loads(f.read().decode())
return {"ok" : False}
@ -69,15 +67,24 @@ def read_channel(id, ts):
for message in messages:
yield message
def print_message(message):
call = call_method_auth("users.info", {"user" : message["user"]})
if call["ok"] == False:
sys.exit(1)
name = "%s %s" % (call["user"]["profile"].get("first_name", ""), call["user"]["profile"].get("last_name", ""))
text = message["text"].encode("utf-8").decode("latin-1")
print("%s: %s" % (name, message["text"].encode("utf-8").decode("latin-1")))
for id in list_channel_ids():
channel = find_channel_info(id)
print(channel["name"])
print("\t%s" % channel["purpose"]["value"])
print("\t%s" % channel["purpose"]["value"].encode("utf-8").decode("latin-1"))
if channel["is_member"]:
print("\tUnread count: %s, last read: %s" % (channel["unread_count"], channel["last_read"]))
if channel["name"] == "maintainers":
for message in read_channel(id, channel["last_read"]):
print(message)
print_message(message)
print()