Create a new Thread class

I want to create a generic class to represent (public) channels and
(private) groups.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-06-09 09:33:50 -04:00
parent c10fff756c
commit fcd2789c29
2 changed files with 24 additions and 15 deletions

View File

@ -1,28 +1,20 @@
#
# Copyright 2015 (c) Anna Schumaker
# Copyright 2015 (c) Anna Schumaker.
#
from . import api
from . import auth
from . import chat
from . import threads
from . import users
class Channel:
class Channel(threads.Thread):
def __init__(self, json):
self.__id = json.get("id", "0")
self.__name = json.get("name", "").title()
threads.Thread.__init__(self, json)
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):
topic=""
if self.__topic != "":
topic = "\nTopic: %s" % self.__topic
return "%s: %s%s" % (self.__name, self.__purpose, topic)
def fetch_info(self):
json = info(self.__id)
if json != None:
@ -35,9 +27,6 @@ class Channel:
def is_member(self):
return self.__member
def name(self):
return self.__name
def post(self, text):
chat.postMessage(self.__id, text)

20
slack/threads.py Normal file
View File

@ -0,0 +1,20 @@
#
# Copyright 2015 (c) Anna Schumaker.
#
class Thread:
def __init__(self, json):
self.__id = json.get("id", 0)
self.__name = json.get("name", "").title()
self.__topic = json["topic"].get("value", "").encode("utf-8").decode("latin-1")
self.__purpose = json["purpose"].get("value", "").encode("utf-8").decode("latin-1")
def __str__(self):
topic=""
if self.__topic != "":
topic = "\nTopic: %s" % self.__topic
return "%s: %s%s" % (self.__name, self.__purpose, topic)
def name(self):
return self.__name