Find channel info and print unread messages
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
883504da38
commit
9065d67acb
46
slackmail.py
46
slackmail.py
|
@ -20,7 +20,9 @@ def call_method(method, args = dict()):
|
|||
|
||||
server = "https://slack.com/api/"
|
||||
with request.urlopen("%s/%s?%s" % (server, method, argstr)) as f:
|
||||
return json.loads(f.read().decode())
|
||||
text = f.read().decode()
|
||||
text = text.replace("\\u2014", " - ")
|
||||
return json.loads(text)
|
||||
return {"ok" : False}
|
||||
|
||||
|
||||
|
@ -37,3 +39,45 @@ if call_method("api.test")["ok"] == False:
|
|||
sys.exit(1)
|
||||
if call_method_auth("auth.test")["ok"] == False:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Find list of channels, we'll get info later
|
||||
#
|
||||
|
||||
def list_channel_ids():
|
||||
call = call_method_auth("channels.list")
|
||||
if call["ok"] == False:
|
||||
sys.exit(1)
|
||||
for channel in call["channels"]:
|
||||
yield channel["id"]
|
||||
|
||||
def find_channel_info(id):
|
||||
call = call_method_auth("channels.info", { "channel" : id })
|
||||
if call["ok"] == False:
|
||||
sys.exit(1)
|
||||
return call["channel"]
|
||||
|
||||
def read_channel(id, ts):
|
||||
args = { "channel" : id, "oldest" : ts }
|
||||
call = call_method_auth("channels.history", args)
|
||||
if call["ok"] == False:
|
||||
sys.exit(1)
|
||||
messages = call["messages"]
|
||||
messages.reverse()
|
||||
for message in messages:
|
||||
yield message
|
||||
|
||||
|
||||
|
||||
for id in list_channel_ids():
|
||||
channel = find_channel_info(id)
|
||||
print(channel["name"])
|
||||
print("\t%s" % channel["purpose"]["value"])
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue