How to use the twython.TwythonError function in twython

To help you get started, we’ve selected a few twython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ryanmcgrath / twython / tests / test_endpoints.py View on Github external
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)
github ryanmcgrath / twython / tests / test_core.py View on Github external
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)
github nellore / vickitrix / vickitrix / __init__.py View on Github external
'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()
github nunoloureiro / birdtradebot / birdtradebot / __init__.py View on Github external
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
github manuelcortez / TWBlue / src / sessions / twitter / session.py View on Github external
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]
github ryanmcgrath / twython / examples / update_status.py View on Github external
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
github wikibook / flask / ch09 / sendtwit.py View on Github external
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)
github veekaybee / soviet-art-bot / soviet-art-bot / lambda_function.py View on Github external
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)
github manuelcortez / TWBlue / src / gui / dialogs / follow.py View on Github external
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()
github mozilla / kitsune / kitsune / customercare / views.py View on Github external
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,