mirror of
https://github.com/nikdoof/test-auth.git
synced 2026-01-31 00:18:14 +00:00
Better handle invalid returns from the API, and recall if we have no messages in the cache
This commit is contained in:
@@ -108,12 +108,15 @@ class Inbox():
|
|||||||
if not self.login_cookie:
|
if not self.login_cookie:
|
||||||
raise NotLoggedIn
|
raise NotLoggedIn
|
||||||
|
|
||||||
if not hasattr(self, '__inbox_cache'):
|
if not hasattr(self, '__inbox_cache') or not len(self.__inbox_cache):
|
||||||
inbox = json.load(self._opener.open(self.REDDIT_API_INBOX))['data']
|
inbox = json.load(self._opener.open(self.REDDIT_API_INBOX))
|
||||||
|
|
||||||
self.__inbox_cache = []
|
if inbox and 'data' in inbox:
|
||||||
for msg in inbox['children']:
|
self.__inbox_cache = []
|
||||||
self.__inbox_cache.append(Message(msg['data']))
|
for msg in inbox['data']['children']:
|
||||||
|
self.__inbox_cache.append(Message(msg['data']))
|
||||||
|
else:
|
||||||
|
self.__inbox_cache = []
|
||||||
|
|
||||||
return self.__inbox_cache
|
return self.__inbox_cache
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user