slack: Find extra channel information if needed

This is mostly to find unread count and timestamp

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-05-26 15:38:47 -04:00
parent 23ac359ad7
commit 4eb177cd8f
2 changed files with 24 additions and 16 deletions

View File

@ -12,6 +12,8 @@ class Channel:
self.__member = json.get("is_member", False)
self.__topic = json["topic"].get("value", "").encode("utf-8").decode("latin-1")
self.__purpose = json["purpose"].get("value", "").encode("utf-8").decode("latin-1")
self.__unread = json.get("unread_count", None)
self.__last_ts = json.get("last_read", None)
def __str__(self):
return "<Channel id:%s name:%s is_member:%s>" % (self.__id, self.__name, self.__member)
@ -19,9 +21,28 @@ class Channel:
def __repr__(self):
return self.__str__()
def fetch_info(self):
json = info(self.__id)
if json != None:
self.__unread = json.get("unread_count", None)
self.__last_ts = json.get("last_read", None)
def is_member(self):
return self.__member
def unread_count(self):
if self.__unread == None:
self.fetch_info()
return self.__unread
def info(channel):
ret = api.call("channels.info", token = auth.token(), channel = channel)
if ret["ok"] == False:
return None
return ret["channel"]
def list():
ret = api.call("channels.list", token = auth.token())

View File

@ -12,26 +12,13 @@ from datetime import datetime
for channel in slack.channels.list():
if not channel.is_member():
continue
print(channel)
if channel.unread_count() == 0 or channel.unread_count() == None:
continue
print(channel, channel.unread_count())
sys.exit(0)
#
# Find list of channels, we'll get info later
#
def list_channel_ids():
call = call_method_auth("channels.list")
if call["ok"] == True:
for channel in call["channels"]:
yield channel["id"]
def find_channel_info(id):
call = call_method_auth("channels.info", { "channel" : id })
if call["ok"] == True:
return call["channel"]
def read_channel(id, ts):
args = { "channel" : id, "oldest" : ts }
call = call_method_auth("channels.history", args)