fix tabs in Jamie's code & add modeline

This commit is contained in:
Kai Hendry
2011-11-13 18:34:31 +00:00
parent 863704da8d
commit 8c8d4a5a8a

View File

@@ -1,10 +1,5 @@
#!/bin/bash #!/bin/bash
# Twitter backup script - hendry AT iki.fi - please mail me suggestions to make this suckless # vim: set ts=4 sw=4
# http://dev.twitter.com/doc/get/statuses/user_timeline
# Known issues:
# API only allows 3200 tweets to be downloaded this way :((
# Won't work on protected accounts (duh!)
# No @mentions or DMs from other accounts
umask 002 umask 002
api="http://api.twitter.com/1/statuses/user_timeline.xml?" api="http://api.twitter.com/1/statuses/user_timeline.xml?"
@@ -48,43 +43,40 @@ echo $?
do do
if test "$REPLY" = $'\r' if test "$REPLY" = $'\r'
then then
break break
else else
echo "$REPLY" >&2 # print header to stderr echo "$REPLY" >&2 # print header to stderr
fi fi
done done
cat; } < $temp > $temp2 cat; } < $temp > $temp2
} 2>&1 | # redirect back to stdout for grep } 2>&1 | # redirect back to stdout for grep
grep -iE 'rate|status' # show the interesting twitter rate limits grep -iE 'rate|status' # show the interesting twitter rate limits
# date --date='@1320361995'
mv $temp2 $temp mv $temp2 $temp
if test $(xmlstarlet sel -t -v "count(//statuses/status)" $temp) -eq 0 if test $(xmlstarlet sel -t -v "count(//statuses/status)" $temp) -eq 0
then then
head $temp
head $temp if test "$2" && test "$since"
if test "$2" && test "$since" then
then echo No old tweets ${since}
echo No old tweets ${since} elif test "$since"
elif test "$since" then
then echo No new tweets ${since}
echo No new tweets ${since} else
else echo "Twitter is returning empty responses on page ${page} :("
echo "Twitter is returning empty responses on page ${page} :(" fi
fi rm -f $temp $temp2
rm -f $temp $temp2 exit
exit
fi fi
xmlstarlet sel -t -m "statuses/status" -n -o "text " -v "text" -m "entities/urls/url" -i "expanded_url != ''" -n -o "url " -v "url" -o " " -v "expanded_url" $temp | { xmlstarlet sel -t -m "statuses/status" -n -o "text " -v "text" -m "entities/urls/url" -i "expanded_url != ''" -n -o "url " -v "url" -o " " -v "expanded_url" $temp | {
while read -r first rest while read -r first rest
do do
case $first in case $first in
"text") echo $text; text=$rest ;; "text") echo $text; text=$rest ;;
"url") set -- $(echo $rest); text=$(echo $text | sed s,$1,$2,g) ;; "url") set -- $(echo $rest); text=$(echo $text | sed s,$1,$2,g) ;;
esac esac
done done
echo $text echo $text
} > $temp2 } > $temp2