From b7c11ba77399f415ec90a920c90230fb24949d0e Mon Sep 17 00:00:00 2001 From: Adi Sieker Date: Wed, 13 Apr 2011 21:01:30 +0200 Subject: [PATCH] refactored fetching of live data the fetch of the data is now in a separate method. Needed when fetching the live stream in a separate thread. If you use the normal live method there'd more api calls to actually get the groups and topics. --- convore/core.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/convore/core.py b/convore/core.py index 430c8c1..f54a896 100644 --- a/convore/core.py +++ b/convore/core.py @@ -50,18 +50,23 @@ class Convore(object): else: return False - def live(self, cursor=None): + + def fetch_live_data(self, cursor=None): params= {} next_cursor = None - live_messages = list() if cursor <> None: params['cursor'] = cursor r = api.get('live', params=params) + return deserialize(r.content)['messages'] + + def live(self, cursor=None): try: - for data in deserialize(r.content)['messages']: + live_messages = list() + messages = self.fetch_live_data(cursor) + for data in messages: try: class_ = LIVE_TYPES[data['kind']] except KeyError: @@ -69,6 +74,7 @@ class Convore(object): message = class_() message.import_from_api(data) + if data['kind'] == 'read': group = self.groups.get(data['group_id']) message.topic = group.topics.get(data['topic_id'])