This script grabs recent 3200+ tweets for a chosen account (-s) using Twitter API and tweepy
library (Python).
extractor.py
- main scriptsettings.py
- file for credentials and list of accounts to grabrealDonaldTrump_tweets.csv
- output after executingextractor.py
. A csv-file with tweets and some features from Donald J. Trump twitter account (grabed on May 24,2018).3200tweets_example.ipynb
- Jupyter Notebook with grabbed data inpandas.DataFrame()
view
- Install
tweepy
$pip install tweepy
-
Create Twitter Application here.
-
Go to the Keys and Access Tokens tab.
-
Open
settings.py
and
- Insert your credentials (in single quotes):
CONSUMER_KEY = 'Consumer Key (API Key)'`
CONSUMER_SECRET = 'Consumer Secret (API Secret)'`
ACCESS_TOKEN = 'Access Token'`
ACCESS_SECRET = 'Access Token Secret'
- Fill the
ACCOUNTS
list with the account (-s) you want to grab (without@
symbol). For example:
ACCOUNTS = ['realDonaldTrump', 'HillaryClinton', 'katyperry', 'jtimberlake']
- Run the script:
$python extractor.py
- Wait until you see the notification:
Finished!
After executing the script you will get csv-file (-s) which contains:
account
- account name (nickname)id
- id of the tweetcreated_at
- date when the tweet was publishedlanguage
- language of the tweettext
- full text of the tweetlikes
- number of likesretweets
- number of retweetshashtags
- hashtag(-s) in the tweetmentions
- account(-s) mentioned in the tweeturls
- url(-s) in the tweet
You can customize which data to grab. Read about Tweet objects and modify extractor.py
as you wish.
No license. Copy, modify and use without any restrictions.