Skip to content

Instantly share code, notes, and snippets.

@Braunson
Forked from jmoz/twitter_favouriter.py
Last active November 17, 2019 06:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Braunson/6144191 to your computer and use it in GitHub Desktop.
Save Braunson/6144191 to your computer and use it in GitHub Desktop.
Converted to work with Python 3.x
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 ("Favourited: {}, {}").format(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 ("Favourited total: %i of %i").format(success, len(result['statuses']))
print ("First id %s last id %s").format(first_id, last_id)
@ErisBlastar
Copy link

Good job, keep up the good work!

@KacemRostom
Copy link

Or just use:
javascript:allFavs=document.getElementsByClassName("favorite"); for(var a=0;a<allFavs.length;a++){ allFavs[a].click(); }
^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment