Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_account(self, user, full_user_object=False):
payload = self._get_twitter_data(user,
full_user_object=full_user_object)
if not payload['timeline']:
raise NoTimelineError(payload['user'])
url = self.bom_api_path('check_account')
bom_resp = self._bom_post(url, json=payload)
bom_resp.raise_for_status()
classification = bom_resp.json()
return classification
def __init__(self, sn, *args, **kwargs):
msg = "user '%s' has no tweets in timeline" % sn
super(NoTimelineError, self).__init__(msg, *args, **kwargs)
def check_accounts_in(self, accounts, full_user_object=False,
on_error=None, **kwargs):
sub_instance = self.create_from(self, wait_on_ratelimit=True,
botometer_api_url=self.api_url)
max_retries = kwargs.get('retries', 3)
for account in accounts:
for num_retries in range(max_retries + 1):
result = None
try:
result = sub_instance.check_account(
account, full_user_object=full_user_object)
except (TweepError, NoTimelineError) as e:
err_msg = '{}: {}'.format(
type(e).__name__,
getattr(e, 'msg', '') or getattr(e, 'reason', ''),
)
result = {'error': err_msg}
except (ConnectionError, HTTPError, Timeout) as e:
if num_retries >= max_retries:
raise
else:
time.sleep(2 ** num_retries)
except Exception as e:
if num_retries >= max_retries:
if on_error:
on_error(account, e)
else:
raise