Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_profile_banner_sizes(self):
"""Test getting list of profile banner sizes fails because
we have not uploaded a profile banner"""
self.assertRaises(TwythonError, self.api.get_profile_banner_sizes)
def test_get_profile_banner_sizes(self):
"""Test getting list of profile banner sizes fails because
we have not uploaded a profile banner"""
self.assertRaises(TwythonError, self.api.get_profile_banner_sizes)
'b) You entered the wrong password above.']
))
exit(1)
print_to_screen('Twitter/GDAX credentials verified.')
# Get all handles to monitor
handles, keywords = set(), set()
for rule in rules:
handles.update(rule['handles'])
keywords.update(rule['keywords'])
handles_to_user_ids = {}
for handle in handles:
try:
handles_to_user_ids[handle] = twitter_client.show_user(
screen_name=handle
)['id_str']
except TwythonError as e:
if 'User not found' in e.message:
print(
'Handle {} not found; skipping rule...'.format(handle)
)
else:
raise
if not handles_to_user_ids:
raise RuntimeError('No followable Twitter handles found in rules!')
while True:
print_to_screen('Listening for tweets; hit CTRL+C to quit...')
trade_listener.statuses.filter(
follow=handles_to_user_ids.values(),
track=list(keywords)
)
print_to_screen(
timestamp()
def twitter_handles_to_userids(twitter, handles):
ids_map = {}
for handle in handles:
try:
ids_map[handle] = twitter.show_user(screen_name=handle)['id_str']
except TwythonError as e:
msg = getattr(e, 'message', None)
if msg is not None and 'User not found' in msg:
log.warning('Handle %s not found; skipping rule...' % handle)
else:
raise
if not ids_map:
raise RuntimeError('No followable Twitter handles found in rules!')
return ids_map
def get_user(self, id):
""" Returns an user object associated with an ID.
id str: User identifier, provided by Twitter.
returns an user dict."""
if ("users" in self.db) == False or (id in self.db["users"]) == False:
try:
user = self.twitter.show_user(id=id)
except TwythonError:
user = dict(screen_name="deleted_account", name="Deleted account")
return user
self.db["users"][user["id_str"]] = user
return user
else:
return self.db["users"][id]
from twython import Twython, TwythonError
# Requires Authentication as of Twitter API v1.1
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
twitter.update_status(status='See how easy this was?')
except TwythonError as e:
print e
from twython import Twython, TwythonError
try:
twitter = Twython(APP_KEY, APP_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
photo = open('Desert.jpg', 'rb')
response = twitter.upload_media(media=photo)
twitter.update_status(status='twit with image!', media_ids=[response['media_id']])
print (json.dumps(response, indent=2, sort_keys=True))
except TwythonError as e:
print (e)
except IOError as e:
print (e)
tmp_dir = tempfile.gettempdir()
call('rm -rf /tmp/*', shell=True)
path = os.path.join(tmp_dir, url)
print(path)
s3_resource.Bucket(bucket_name).download_file(url, path)
print("file moved to /tmp")
print(os.listdir(tmp_dir))
with open(path, 'rb') as img:
print("Path", path)
twit_resp = twitter.upload_media(media=img)
twitter.update_status(status="\"%s\"\n%s, %s" % (title, painter, year), media_ids=twit_resp['media_id'])
except TwythonError as e:
print(e)
def onok(self, ev):
if self.follow.GetValue() == True:
try:
self.parent.twitter.twitter.create_friendship(screen_name=self.cb.GetValue())
self.Destroy()
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
elif self.unfollow.GetValue() == True:
try:
id = self.parent.twitter.twitter.destroy_friendship(screen_name=self.cb.GetValue())
self.Destroy()
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
elif self.mute.GetValue() == True:
try:
id = self.parent.twitter.twitter.create_mute(screen_name=self.cb.GetValue())
if config.main["other_buffers"]["show_muted_users"] == True:
tweet_event = event.event(event.EVT_OBJECT, 1)
tweet_event.SetItem(id)
wx.PostEvent(self.parent.parent.nb.GetPage(self.parent.db.settings["buffers"].index("muteds")), tweet_event)
self.parent.db.settings["muted_users"].append(id["id"])
self.Destroy()
except RedisError as e:
statsd.incr('redis.errror')
log.error('Redis error: %s' % e)
contributor_stats = redis and redis.get(settings.CC_TOP_CONTRIB_CACHE_KEY)
if contributor_stats:
contributor_stats = json.loads(contributor_stats)
statsd.incr('customercare.stats.contributors.hit')
else:
statsd.incr('customercare.stats.contributors.miss')
twitter_user = None
if request.twitter.authed:
try:
credentials = request.twitter.api.verify_credentials()
except (TwythonError, TwythonAuthError):
# Bad oauth token. Create a new session so user re-auths.
request.twitter = twitter.Session()
else:
twitter_user = credentials['screen_name']
yesterday = datetime.now() - timedelta(days=1)
recent_replied_count = _count_answered_tweets(since=yesterday)
return render(request, 'customercare/landing.html', {
'contributor_stats': contributor_stats,
'canned_responses': get_common_replies(request.LANGUAGE_CODE),
'tweets': _get_tweets(locale=request.LANGUAGE_CODE,
filter='unanswered',
https=request.is_secure()),
'authed': request.user.is_authenticated() and request.twitter.authed,