Skip to content

Instantly share code, notes, and snippets.

@ErisBlastar
Forked from jmoz/twitter_favouriter.py
Last active October 19, 2020 07:48

Revisions

  1. ErisBlastar revised this gist Aug 3, 2013. 1 changed file with 20 additions and 8 deletions.
    28 changes: 20 additions & 8 deletions twitter_favouriter.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,15 @@
    # Original by James Morris JMOZ at: http://blog.jmoz.co.uk/increase-your-twitter-followers/
    # Modified by Eris Blastar http://iwethey.neocities.org/ [email protected] to encode UTF-8 strings in case
    # of foriegn language and odd characters. PS you will need Python 2.7 as Python 3.X won't work
    # and of course the Twitter library https://pypi.python.org/pypi/twitter
    # plus the setuptool to install the library the Windows version is here: http://www.lfd.uci.edu/~gohlke/pythonlibs/
    # You need your API key from https://dev.twitter.com/discussions/631 and make sure it isn't set to
    # read-only when you make the access token.
    # Good luck, Eris.

    from twitter import Twitter, OAuth, TwitterHTTPError
    # -*- coding: utf-8 -*-
    import sys


    OAUTH_TOKEN = 'foo'
    @@ -8,21 +19,22 @@

    t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET))


    print sys.stdout.encoding

    def search_tweets(q, count=100, max_id=None):
    return t.search.tweets(q=q, result_type='recent', count=count, lang="en", max_id=max_id)


    def favorites_create(tweet):
    try:
    result = t.favorites.create(_id=tweet['id'])
    print "Favorited: %s, %s" % (result['text'], result['id'])
    print "Favorited: %s, %s" % (result['text'].encode(sys.stdout.encoding, errors='replace'), result['id'])
    return result
    except TwitterHTTPError as e:
    print "Error: ", e
    return None


    def search_and_fav(q, count=100, max_id=None):
    result = search_tweets(q, count, max_id)
    first_id = result['statuses'][0]['id']
    @@ -31,6 +43,6 @@ def search_and_fav(q, count=100, max_id=None):
    for t in result['statuses']:
    if favorites_create(t) is not None:
    success += 1

    print "Favorited total: %i of %i" % (success, len(result['statuses']))
    print "First id %s last id %s" % (first_id, last_id)
    print "First id %s last id %s" % (first_id, last_id)
  2. James Morris created this gist Aug 1, 2013.
    36 changes: 36 additions & 0 deletions twitter_favouriter.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    from twitter import Twitter, OAuth, TwitterHTTPError


    OAUTH_TOKEN = 'foo'
    OAUTH_SECRET = 'bar'
    CONSUMER_KEY = 'baz'
    CONSUMER_SECRET = 'bat'

    t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET))


    def search_tweets(q, count=100, max_id=None):
    return t.search.tweets(q=q, result_type='recent', count=count, lang="en", max_id=max_id)


    def favorites_create(tweet):
    try:
    result = t.favorites.create(_id=tweet['id'])
    print "Favorited: %s, %s" % (result['text'], result['id'])
    return result
    except TwitterHTTPError as e:
    print "Error: ", e
    return None


    def search_and_fav(q, count=100, max_id=None):
    result = search_tweets(q, count, max_id)
    first_id = result['statuses'][0]['id']
    last_id = result['statuses'][-1]['id']
    success = 0
    for t in result['statuses']:
    if favorites_create(t) is not None:
    success += 1

    print "Favorited total: %i of %i" % (success, len(result['statuses']))
    print "First id %s last id %s" % (first_id, last_id)