Last active
September 18, 2016 18:43
-
-
Save amar061996/227f3472f9d08a9028d0 to your computer and use it in GitHub Desktop.
Extracts desired number of tweets from any user on twitter whose twitter username is provided
This file contains hidden or 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 | |
| from tweepy import OAuthHandler | |
| import io | |
| def twitter_user(username,num): | |
| fw=io.open("twitter_user.txt",'a',encoding='utf8') | |
| ckey='Your Consumer Key' | |
| csecrett='Your Consumer Secret' | |
| atoken='Your Access Token' | |
| asecret='Your Access Secret' | |
| auth=OAuthHandler(ckey,csecret) | |
| auth.set_access_token(atoken,asecret) | |
| api=tweepy.API(auth) | |
| user_tweets=api.user_timeline(screen_name=username,count=num) | |
| for tweet in user_tweets: | |
| fw.write(tweet.text+"\n") | |
| print tweet.text | |
| fw.close() | |
| user=raw_input("Enter the username: ") | |
| noT=raw_input("Enter the number of tweets required: ") | |
| print "Tweets for the user: "+user+"\n" | |
| twitter_user(user,noT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment