I gave in to my paranoid tendencies today and wrote a little backup script for Twitter, which I figured I'd share here.
Two requirements:
To install these from the terminal:
gem install t # Assumes that you have Ruby installed already
sudo easy_install csvkit # More info: https://github.com/amandabee/CUNY-data-storytelling/wiki/Tutorial:-Installing-CSVKit
Here's the script to do the backup itself (which I plan to run ~1/mo):
#!/bin/sh
export DAY=`date +'%Y-%m-%d'`
user=devonzuegel
tweetsFile="$DAY--$user--tweets.csv"
retweetsFile="$DAY--$user--retweets.csv"
favoritesFile="$DAY--$user--favorites.csv"
followingsFile="$DAY--$user--followings.csv"
max=10000
echo "Backing up tweets..."; t timeline ${user} --csv --number ${max} > "${tweetsFile}"
echo "Backing up retweets..."; t retweets ${user} --csv --number ${max} > "${retweetsFile}"
echo "Backing up favorites..."; t favorites ${user} --csv --number ${max} > "${favoritesFile}"
echo "Backing up followings..."; t followings ${user} --csv > "${followingsFile}"
echo "\nBacked up the following for ${user}'s data:"
numTweetsWithLabel=$(csvstat --count ${tweetsFile})
numTweets="${numTweetsWithLabel#"Row count: "}"
numRetweetsWithLabel=$(csvstat --count ${retweetsFile})
numRetweets="${numRetweetsWithLabel#"Row count: "}"
numFavoritesWithLabel=$(csvstat --count ${favoritesFile})
numFavorites="${numFavoritesWithLabel#"Row count: "}"
numFollowingsWithLabel=$(csvstat --count ${followingsFile})
numFollowings="${numFollowingsWithLabel#"Row count: "}"
echo "- ${numTweets} tweets"
echo "- ${numRetweets} retweets"
echo "- ${numFavorites} favorites"
echo "- ${numFollowings} followings"
echo "\nDone 🎉\n"
For some reason it's only retrieving ~3,000 of my tweets (when I have 5,000+). From a quick perusal of the web, several people mentioned that Twitter has limited this API to just 3,200 results. Bummer! Should still work for most folks, plus I like the CSV format.
You can also retrieve a full backup by going to your Account Settings and requesting "Your Tweet Archive" at the bottom. It gives you a nice little viewer too! And this one gives you all of your tweets, not just the last 3,000. 🙂 I like having both formats.