Return on exception

This commit is contained in:
Manuel Cortez 2022-07-29 17:27:48 -05:00
parent 6fcd0274a9
commit f01ad5abb7
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
2 changed files with 9 additions and 8 deletions

View File

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
""" Scanning code for autocompletion feature on TWBlue. This module can retrieve user objects from the selected Twitter account automatically. """
import time
import threading
import wx
import widgetUtils
import output
from tweepy.cursor import Cursor
from tweepy.errors import TweepyException
from pubsub import pub
from mysc.thread_utils import call_threaded
from . import wx_scan
from . import manage
from . import storage
@ -36,7 +36,8 @@ class autocompletionScan(object):
self.progress_dialog = wx_scan.get_progress_dialog(parent=self.dialog)
# connect method to update progress dialog
pub.subscribe(self.on_update_progress, "on-update-progress")
scanner = call_threaded(self.scan)
scanner = threading.Thread(target=self.scan)
scanner.start()
def on_update_progress(self, percent):
if percent > 100:
@ -64,7 +65,7 @@ class autocompletionScan(object):
ids.append(str(i))
except TweepyException:
wx.CallAfter(wx_scan.show_error)
self.done()
return 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.
@ -74,9 +75,10 @@ class autocompletionScan(object):
continue
try:
results = selff.buffer.session.twitter.lookup_users(user_id=z)
except TweepyException:
except NameError:
wx.CallAfter(wx_scan.show_error)
self.done()
wx.CallAfter(self.dialog.SetFocus)
return self.done()
users.extend(results)
time.sleep(1)
percent = percent + (100/len(split_users))

View File

@ -31,6 +31,5 @@ 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()
with wx.MessageDialog(None, _("Error adding users from Twitter. Please try again in about 15 minutes."), _("Error"), style=wx.ICON_ERROR) as dlg:
dlg.ShowModal()