Is there a simple way to retrieve someone's tweets from the command line?
The account would be public, and the command - or script, if necessary - would retrieve all or a specified number of most recent tweets to a text file, one tweet per line, without the metadata, the newest in the first line.
Without the use of API, only bash.
From a-close-date on, Twitter won't let you into their API without having an OAuth key. But as a workaround you can use Search API. It is RESTful, so you can use
curl
to retrieve search results in JSON format. For example, if you want to retrieve @java's tweets, and save it to file~/.tweets
, this line of code can be used:And you can parse the file, using any JSON parser.
The
rpp
parameter is number af tweets to be retrieved.callback
is javascript function to be executed on the resulting JSON. In case you're not using JavaScript with the api, you can leave it ?, but don't remove it. I will cause an error. More guidance on Search api can be found on https://dev.twitter.com/docs/api/1/get/searchThere are tools to parse JSON from command line interface. Although I've never used one, I'll put some links to some resources, to help you find out the best suited tool:
And as a little note, it is quicker to use some Python or Ruby (or others).
If you don't want to use the Twitter API, you could grab the RSS feed of the Twitter profile using a bash script and then proceed to format it from there.
Since Twitter API has deprecated the RSS feed, you can workaround this by generating RSS feed using the search results.
Here's the RSS feed of my tweets.
You would have to put together the necessary bash script though. From fetching the RSS feed to formatting the tweets as per your requirements.
This is my script made for screensaver usage
You can use
twarc
to give an example if you want to archive Nassim Nicholas Taleb's tweets you use.You can use other formats too:
--format {json,csv,csv-excel}
How to configure
twarc
: The only way to get the complete tweets is using theAPI
unfortunately even if the app is transparent you need to have an initial setup and configuration, you also need to apply for theAPI
()
Once you've got your application keys you can tell
twarc
what they are with the configure command.This will store your credentials in a file called
.twarc
in your home directory so you don't have to keep entering them in. If you would rather supply them directly you can set them in the environment (CONSUMER_KEY
,CONSUMER_SECRET
,ACCESS_TOKEN
,ACCESS_TOKEN_SECRET
) or using command line options (--consumer_key
,--consumer_secret
,--access_token
,--access_token_secret
).I made a tool that should do almost exactly what you described: twitter-screen-scrape . By default it will output in JSON, with metadata, but it's trivial to pipe the output through something like underscore-cli to strip out everything you don't want.
You could go the python + tweepy route by:
I just tested it and it works great. There are however users that protect their tweets, so it might not let you download everything. But that's a feature of twitter.
Limit still is 3200 and you get a CSV file.