Last active
August 29, 2015 14:22
-
-
Save d7my11/0c97765f0448c5501984 to your computer and use it in GitHub Desktop.
Favorite last 100 tweets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import argparse | |
def main(handle): | |
try: | |
CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxx' | |
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | |
ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | |
ACCESS_TOKEN_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxx' | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) | |
api = tweepy.API(auth) | |
tweets = api.user_timeline(screen_name=handle, count=100, include_rts=False) | |
tweet_ids = [t.id for t in tweets] | |
"""Favorite""" | |
for t in tweet_ids: | |
api.create_favorite(t) | |
print "favorite %d tweets." % len(tweet_ids) | |
print "Done" | |
# """Unfavorite""" | |
# for t in tweet_ids: | |
# api.destroy_favorite(t) | |
except: | |
print "Error" | |
if __name__ == "__main__": | |
description = """ Favorite last 100 tweets """ | |
favorite_help = 'provide twitter handle to favorite last 100 tweet(s)' | |
parser = argparse.ArgumentParser(description=description) | |
parser.add_argument('-hle', '--handle', help=favorite_help) | |
args = parser.parse_args() | |
main(str(args.handle)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create twitter app from https://apps.twitter.com | |
Provide CONSUMER_KEY, CONSUMER_SECRET .... | |
Command Line: python favorite.py -hle <twitter handle> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment