Added exception handling to scan for users

This commit is contained in:
Manuel Cortez 2022-07-29 13:30:43 -05:00
parent 654b34c8e1
commit 6fcd0274a9
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
2 changed files with 21 additions and 8 deletions

View File

@ -39,7 +39,6 @@ class autocompletionScan(object):
scanner = call_threaded(self.scan)
def on_update_progress(self, percent):
print(percent)
if percent > 100:
percent = 100
wx.CallAfter(self.progress_dialog.Update, percent)
@ -59,25 +58,34 @@ class autocompletionScan(object):
ids.append(str(i))
# same step, but for followers.
if self.dialog.get("followers") == True:
for i in Cursor(self.buffer.session.twitter.get_follower_ids, count=5000).items():
if str(i) not in ids:
ids.append(str(i))
try:
for i in Cursor(self.buffer.session.twitter.get_follower_ids, count=5000).items():
if str(i) not in ids:
ids.append(str(i))
except TweepyException:
wx.CallAfter(wx_scan.show_error)
self.done()
# As next step requires batches of 100s users, let's split our user Ids so we won't break the param rules.
split_users = [ids[i:i + 100] for i in range(0, len(ids), 100)]
# store returned users in this list.
users = []
for z in split_users:
if len(z) == 0:
print("Invalid user count")
continue
print(len(z))
results = self.buffer.session.twitter.lookup_users(user_id=z)
try:
results = selff.buffer.session.twitter.lookup_users(user_id=z)
except TweepyException:
wx.CallAfter(wx_scan.show_error)
self.done()
users.extend(results)
time.sleep(1)
percent = percent + (100/len(split_users))
pub.sendMessage("on-update-progress", percent=percent)
for user in users:
database.set_user(user.screen_name, user.name, 1)
self.done()
def done(self):
wx.CallAfter(self.progress_dialog.Destroy)
wx.CallAfter(self.dialog.Destroy)
pub.unsubscribe(self.on_update_progress, "on-update-progress")

View File

@ -22,10 +22,15 @@ class autocompletionScanDialog(widgetUtils.BaseDialog):
self.SetClientSize(sizer.CalcMin())
def confirm():
with wx.MessageDialog(None, _("This process will retrieve the users you selected from Twitter, and add them to the user autocomplete database. Please note that if there are many users or you have tried to perform this action less than 15 minutes ago, TWBlue may reach a limit in Twitter API calls when trying to load the users into the database. If this happens, we will show you an error, in which case you will have to try this process again in a few minutes. If this process finish with no error, you will be redirected back to the account settings dialog. Do you want to continue?"), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO) as result:
with wx.MessageDialog(None, _("This process will retrieve the users you selected from Twitter, and add them to the user autocomplete database. Please note that if there are many users or you have tried to perform this action less than 15 minutes ago, TWBlue may reach a limit in Twitter API calls when trying to load the users into the database. If this happens, we will show you an error, in which case you will have to try this process again in a few minutes. If this process ends with no error, you will be redirected back to the account settings dialog. Do you want to continue?"), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO) as result:
if result.ShowModal() == wx.ID_YES:
return True
return False
def get_progress_dialog(parent=None):
return wx.ProgressDialog(_("Retrieving Twitter users from account..."), _("working..."), parent=parent, maximum=100, style=wx.PD_APP_MODAL)
def show_error():
dlg = wx.MessageDialog(None, _("Error adding users from Twitter. Please try again in about 15 minutes."), _("Error"), style=wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()