Write unread messages to a temporary file
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
11a777cb76
commit
fdc2c9970e
27
slackmail.py
27
slackmail.py
|
@ -2,6 +2,7 @@
|
|||
# Copyright 2015 (c) Anna Schumaker.
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from urllib import request
|
||||
|
@ -65,12 +66,12 @@ def read_channel(id, ts):
|
|||
for message in messages:
|
||||
yield message
|
||||
|
||||
def _print_message(user, message):
|
||||
def _write_message(fout, user, message):
|
||||
dt = datetime.fromtimestamp(float(message["ts"]))
|
||||
text = message["text"].encode("utf-8").decode("latin-1")
|
||||
print("%s %s: %s" % (str(dt), user, text))
|
||||
fout.write("%s %s: %s\n" % (str(dt), user, text))
|
||||
|
||||
def print_message(message):
|
||||
def write_message(fout, message):
|
||||
call = call_method_auth("users.info", {"user" : message["user"]})
|
||||
if call["ok"] == False:
|
||||
name = message["user"]
|
||||
|
@ -80,16 +81,20 @@ def print_message(message):
|
|||
name = "%s %s" % (first, last)
|
||||
if first == "" and last == "":
|
||||
name = call["user"]["name"]
|
||||
_print_message(name, message)
|
||||
_write_message(fout, name, message)
|
||||
|
||||
|
||||
|
||||
os.mkdir("/tmp/slackmail/")
|
||||
for id in list_channel_ids():
|
||||
channel = find_channel_info(id)
|
||||
print(channel["name"])
|
||||
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"]))
|
||||
for message in read_channel(id, channel["last_read"]):
|
||||
print_message(message)
|
||||
print()
|
||||
if not channel["is_member"]:
|
||||
continue
|
||||
if channel["unread_count"] == 0:
|
||||
continue
|
||||
fout = open("/tmp/slackmail/%s" % channel["name"], 'w')
|
||||
fout.write(channel["purpose"]["value"].encode("utf-8").decode("latin-1"))
|
||||
fout.write("\n")
|
||||
for message in read_channel(id, channel["last_read"]):
|
||||
write_message(fout, message)
|
||||
fout.close()
|
||||
|
|
Loading…
Reference in New Issue