mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Added exception handling to scan for users
This commit is contained in:
parent
654b34c8e1
commit
6fcd0274a9
@ -39,7 +39,6 @@ class autocompletionScan(object):
|
|||||||
scanner = call_threaded(self.scan)
|
scanner = call_threaded(self.scan)
|
||||||
|
|
||||||
def on_update_progress(self, percent):
|
def on_update_progress(self, percent):
|
||||||
print(percent)
|
|
||||||
if percent > 100:
|
if percent > 100:
|
||||||
percent = 100
|
percent = 100
|
||||||
wx.CallAfter(self.progress_dialog.Update, percent)
|
wx.CallAfter(self.progress_dialog.Update, percent)
|
||||||
@ -59,25 +58,34 @@ class autocompletionScan(object):
|
|||||||
ids.append(str(i))
|
ids.append(str(i))
|
||||||
# same step, but for followers.
|
# same step, but for followers.
|
||||||
if self.dialog.get("followers") == True:
|
if self.dialog.get("followers") == True:
|
||||||
|
try:
|
||||||
for i in Cursor(self.buffer.session.twitter.get_follower_ids, count=5000).items():
|
for i in Cursor(self.buffer.session.twitter.get_follower_ids, count=5000).items():
|
||||||
if str(i) not in ids:
|
if str(i) not in ids:
|
||||||
ids.append(str(i))
|
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.
|
# 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)]
|
split_users = [ids[i:i + 100] for i in range(0, len(ids), 100)]
|
||||||
# store returned users in this list.
|
# store returned users in this list.
|
||||||
users = []
|
users = []
|
||||||
for z in split_users:
|
for z in split_users:
|
||||||
if len(z) == 0:
|
if len(z) == 0:
|
||||||
print("Invalid user count")
|
|
||||||
continue
|
continue
|
||||||
print(len(z))
|
try:
|
||||||
results = self.buffer.session.twitter.lookup_users(user_id=z)
|
results = selff.buffer.session.twitter.lookup_users(user_id=z)
|
||||||
|
except TweepyException:
|
||||||
|
wx.CallAfter(wx_scan.show_error)
|
||||||
|
self.done()
|
||||||
users.extend(results)
|
users.extend(results)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
percent = percent + (100/len(split_users))
|
percent = percent + (100/len(split_users))
|
||||||
pub.sendMessage("on-update-progress", percent=percent)
|
pub.sendMessage("on-update-progress", percent=percent)
|
||||||
for user in users:
|
for user in users:
|
||||||
database.set_user(user.screen_name, user.name, 1)
|
database.set_user(user.screen_name, user.name, 1)
|
||||||
|
self.done()
|
||||||
|
|
||||||
|
def done(self):
|
||||||
wx.CallAfter(self.progress_dialog.Destroy)
|
wx.CallAfter(self.progress_dialog.Destroy)
|
||||||
wx.CallAfter(self.dialog.Destroy)
|
wx.CallAfter(self.dialog.Destroy)
|
||||||
pub.unsubscribe(self.on_update_progress, "on-update-progress")
|
pub.unsubscribe(self.on_update_progress, "on-update-progress")
|
||||||
|
@ -22,10 +22,15 @@ class autocompletionScanDialog(widgetUtils.BaseDialog):
|
|||||||
self.SetClientSize(sizer.CalcMin())
|
self.SetClientSize(sizer.CalcMin())
|
||||||
|
|
||||||
def confirm():
|
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:
|
if result.ShowModal() == wx.ID_YES:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_progress_dialog(parent=None):
|
def get_progress_dialog(parent=None):
|
||||||
return wx.ProgressDialog(_("Retrieving Twitter users from account..."), _("working..."), parent=parent, maximum=100, style=wx.PD_APP_MODAL)
|
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()
|
Loading…
Reference in New Issue
Block a user