Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
com.vsubhash.bash.twitter-to-pdf.txt is a Unix/Linux shell script for saving all messages posted by a Twitter account as an archive in PDF format.
if [ $# -lt 2 ]; then
echo -e "The format is:\n\t\e[35m`basename $0` \e[35;1mtwitter-handle-or-hashtag number-of-tweets [nojs]\e[0m"
exit
fi
# A backup of all files will be available in this Logs directory
if [ ! -d ~/Logs ]; then
mkdir ~/Logs
fi
cd ~/Logs
# Declare variables
iTweetsPerPage=100
iPage=1
iMaxPages=1
iRemainder=0
sDocs=""
# Initialize variables
let "iMaxPages = $2 / $iTweetsPerPage"
let "iRemainder = $2 % $iTweetsPerPage"
if [ $iRemainder -gt 0 ]; then
let "iMaxPages = iMaxPages + 1"
fi
# Javascript to remove YouTube IFrames.
sJavaScript="(function(){var arIframes=document.getElementsByTagName('iframe');var n = arIframes.length; for (var i=0;i<n;i++){ arIframes[0].parentElement.removeChild(arIframes[0]);}})()"
# If Javascript scripts cause problems, use the "nojs" argument to this
# shell script
if [ $# -eq 3 ]; then
sJavaScriptFlag="--disable-javascript"
else
sJavaScriptFlag="--enable-javascript"
fi
# Create archives
for (( iPage=1; iPage $1-meta.txt
echo "InfoValue: Subhash TweetsToRSS (www.vsubhash.com)" >> $1-meta.txt
echo "InfoKey: Title" >> $1-meta.txt
echo "InfoValue: The complete Twitter archive of $1" >> $1-meta.txt
echo "InfoKey: Subject" >> $1-meta.txt
echo "InfoValue: Collection of all tweets from $1" >> $1-meta.txt
echo "InfoKey: Author" >> $1-meta.txt
echo "InfoValue: $1" >> $1-meta.txt
echo "InfoKey: Keywords" >> $1-meta.txt
echo "InfoValue: $1, twitter, tweets, archive" >> $1-meta.txt
pdftk Complete-Twitter-Archive-of-$1.pdf \
update_info $1-meta.txt \
output The-Complete-Twitter-Archive-of-$1.pdf
if [ $# -eq 0 ]; then
notify-send "Twitter archive" "Completed for @$1"
else
notify-send "Twitter archive" "Error occurred for @$1"
fi
if [ -f The-Complete-Twitter-Archive-of-$1.pdf ]; then
cp ./The-Complete-Twitter-Archive-of-$1.pdf ~/Desktop/The-Complete-Twitter-Archive-of-$1.pdf
fi
# Cleanup
if [ ! -d $1-backup ]; then
mkdir $1-backup
fi
if [ -d $1-backup ]; then
mv -f $1-archive-*.pdf ./$1-backup
mv -f Complete-Twitter-Archive-of-$1.pdf ./$1-backup
mv -f $1-meta.txt ./$1-backup
mv ./The-Complete-Twitter-Archive-of-$1.pdf ./$1-backup
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.