Created
June 20, 2012 16:41
-
-
Save oliveiraev/2960853 to your computer and use it in GitHub Desktop.
Baixa todos os tuítes de um usuário com timeline pública
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/bash | |
if [ ! -d './downloaded_tweets' ]; then | |
mkdir downloaded_tweets | |
if [ ! -d './downloaded_tweets' ]; then | |
echo "Can't create output dir." > /dev/stderr | |
exit 1 | |
fi | |
fi | |
cd downloaded_tweets | |
while [ "$1" != "" ]; do | |
tweets="`curl -s https://api.twitter.com/1/users/lookup.json?screen_name=$1`" | |
tweets=`echo $tweets | sed -r -e 's!.*?"statuses_count":([0-9]+).*!\1!'` | |
pages=$(( $tweets / 200 )) | |
if [ $(( $tweets % 200 )) ]; then pages=$(( $pages + 1 )); fi | |
i=1 | |
while [ $i -le $pages ]; do | |
echo "Downloading from $1: Page $i of $pages" | |
curl -s https://api.twitter.com/1/statuses/user_timeline.xml\?screen_name=$1\&count=200\&page=$i >> /tmp/tweets.xml | |
i=$(( i + 1 )) | |
done | |
sed -r -i -e's/<\?xml version="1.0" encoding="UTF-8"\?>//' -e 's/<statuses type="array">//' -e 's!</statuses>!!' /tmp/tweets.xml | |
echo '<?xml version="1.0" encoding="UTF-8"?> | |
<statuses type="array">' > $1-tweets.xml | |
cat /tmp/tweets.xml >> $1-tweets.xml | |
echo '</statuses>' >> $1-tweets.xml | |
rm /tmp/tweets.xml | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: $ ./download_tweets.sh twitter twitterapi anotheruser