From c8b4fb18284811b194a02bfa55ee1b7b893a60c0 Mon Sep 17 00:00:00 2001 From: tt Date: Thu, 6 Oct 2016 02:28:57 -0400 Subject: [PATCH] Add 1.5 second wait time when logging into Cytube to let rank initialize. See also #85. --- .gitignore | 2 ++ connections/cytube/cyClient.py | 17 ++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index bd5dc18..38bd87d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.py[cod] *.db +*.db-shm +*.db-wal *.swp *.flv *.json diff --git a/connections/cytube/cyClient.py b/connections/cytube/cyClient.py index 9a6744a..d7e41b6 100644 --- a/connections/cytube/cyClient.py +++ b/connections/cytube/cyClient.py @@ -171,7 +171,10 @@ def onOpen(self): self.lifeline = None self.heartbeat.start(20.0, now=True) self.finalHeartbeat = None - self.initialize() + # wait one second before logging in + # to make sure rank is properly initialized + # eventually check for "rank" frame + reactor.callLater(1.5, self.initialize) def abandon(self): """ @@ -724,14 +727,10 @@ def userJoin(self, user, timeNow): # add a reference to the deferred to the userdict self.userdict[user['name']]['deferred'] = d - try: - profileText = user['profile']['text'] - profileImgUrl = user['profile']['image'] - except: - p = json.loads(user['profile']) - clog.error(p) - profileText = p['text'] - profileImgUrl = p['image'] + profileText, profileImgUrl = (None, None) + if user.get('profile'): + profileText = user['profile'].get('text') + profileImgUrl = user['profile'].get('image') d.addCallback(self.updateProfile, profileText, profileImgUrl) def updateProfile(self, userId, profileText, profileImgUrl):