Created
March 16, 2010 04:59
-
-
Save dsc/333661 to your computer and use it in GitHub Desktop.
Downloads your Flickr stats.
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 | |
function usage () { | |
echo | |
echo "Usage: $0 USERNAME COOKIES" | |
echo | |
echo "Easiest Way to Get Your Cookies:" | |
echo " I recommend you use firebug on a visit to http://www.flickr.com and copy the value of the Cookie header from your first request." | |
} | |
function lolwut () { | |
echo "shit's fucked!" | |
exit 1 | |
} | |
case "$1" in | |
-h | --h | --he | --hel | --help ) | |
usage; exit 0 ;; | |
esac | |
if test "$1"; then | |
USERNAME="$1" | |
else | |
echo "You must supply your Flickr username!" | |
usage | |
exit 1 | |
fi | |
if test "$2"; then | |
COOKIES="$2" | |
else | |
echo "You must supply your Flickr cookies!" | |
usage | |
exit 1 | |
fi | |
mkdir -p "flickr-stats" | |
cd flickr-stats | |
FLICKR="http://www.flickr.com" | |
AGENT='Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6' | |
echo "Snarfing download URLs..." | |
curl -b "$COOKIES" -A "$AGENT" --url "$FLICKR/photos/$USERNAME/stats/downloads" > downloads.html | |
test "$?" != 0 && lolwut | |
echo "And now, the CSVs..." | |
for csv in $(grep -o "photos/$USERNAME/stats/downloads/csv/.*y.csv" downloads.html); do | |
echo | |
echo "$FLICKR/$csv" | |
curl -b "$COOKIES" -A "$AGENT" --url "$FLICKR/$csv" > "$(basename $csv)" | |
test "$?" != 0 && lolwut | |
done | |
echo "Done!" | |
cd .. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment