Skip to content

Instantly share code, notes, and snippets.

@xoebus
Created May 7, 2012 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoebus/2629277 to your computer and use it in GitHub Desktop.
Save xoebus/2629277 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
# A twitter backup script.
function line_count {
echo `cat $1 | wc -l | sed -e 's/^[ \t]*//'`
}
# Setup
mkdir -p `pwd`/archives
DAY=`date +'%Y-%m-%d'`
USERNAME='@xoebus'
echo "Backing up timeline..."
t timeline $USERNAME --csv --number 3000 > tweets-$DAY.csv
echo "Backing up retweets..."
t retweets --csv --number 3000 > retweets-$DAY.csv
echo "Backing up favourites..."
t favorites --csv --number 3000 > favorites-$DAY.csv
echo "Backing up received DMs..."
t direct_messages --csv --number 3000 > dm_received-$DAY.csv
echo "Backing up sent DMs..."
t direct_messages_sent --csv --number 3000 > dm_sent-$DAY.csv
echo "Backing up followings..."
t followings --csv > followings-$DAY.csv
echo "\nBacked up the following:"
echo " -" $(line_count tweets-$DAY.csv) "tweets"
echo " -" $(line_count retweets-$DAY.csv) "retweets"
echo " -" $(line_count favorites-$DAY.csv) "favorites"
echo " -" $(line_count dm_received-$DAY.csv) "DM received"
echo " -" $(line_count dm_sent-$DAY.csv) "DM sent"
echo " -" $(line_count followings-$DAY.csv) "followings"
echo "\nArchiving..."
tar -czf archive-$DAY.tar.gz *.csv
mv archive-$DAY.tar.gz archives
echo "Cleaning up..."
rm *.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment