Last active
December 31, 2020 01:01
-
-
Save devonzuegel/afaf87f11518e38908057a88e8afadd9 to your computer and use it in GitHub Desktop.
Backup your Twitter data
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
#!/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" |
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment