Better handle invalid returns from the API, and recall if we have no messages in the cache

This commit is contained in:
2011-06-24 09:15:12 +01:00
parent e8d384ec88
commit 62c089a095

View File

@@ -108,12 +108,15 @@ class Inbox():
if not self.login_cookie:
raise NotLoggedIn
if not hasattr(self, '__inbox_cache'):
inbox = json.load(self._opener.open(self.REDDIT_API_INBOX))['data']
self.__inbox_cache = []
for msg in inbox['children']:
self.__inbox_cache.append(Message(msg['data']))
if not hasattr(self, '__inbox_cache') or not len(self.__inbox_cache):
inbox = json.load(self._opener.open(self.REDDIT_API_INBOX))
if inbox and 'data' in inbox:
self.__inbox_cache = []
for msg in inbox['data']['children']:
self.__inbox_cache.append(Message(msg['data']))
else:
self.__inbox_cache = []
return self.__inbox_cache