Last active
August 29, 2015 13:58
-
-
Save joeymink/9955141 to your computer and use it in GitHub Desktop.
Queries Flickr for the last upload by the given user
This file contains hidden or 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 | |
| #### | |
| # last_flickr.sh | |
| # | |
| # Queries Flickr's APIs for the last upload by the given user. | |
| # (Only tested on OSX) | |
| ## | |
| function usage { | |
| echo "Usage:" | |
| echo "last_flickr <api key> <username>" | |
| exit 1 | |
| } | |
| if [ -z $1 ] || [ -z $2 ]; then | |
| usage | |
| fi | |
| API_KEY=$1 | |
| USERNAME=$2 | |
| #### | |
| # Make call to find NSID for username | |
| ## | |
| METHOD=flickr.people.findByUsername | |
| URL="https://api.flickr.com/services/rest/?method=$METHOD&api_key=$API_KEY&username=$2" | |
| wget -O user.html $URL --output-file user.log | |
| NSID=`grep nsid=\".*\" user.html --only-match | grep \".*\" --only-match | sed s/\"//g` | |
| #### | |
| # Find most recent photo | |
| ## | |
| METHOD=flickr.people.getPublicPhotos | |
| URL="https://api.flickr.com/services/rest/?method=$METHOD&api_key=$API_KEY&user_id=$NSID&per_page=1&page=1&extras=date_upload" | |
| wget -O photos.html $URL --output-file photos.log | |
| DATE_UPLOAD=`grep dateupload=\"[0-9]*\" photos.html --only-matching | grep [0-9][0-9]* --only-matching` | |
| READABLE_DATE=`date -r $DATE_UPLOAD` | |
| echo "Last photo was uploaded to Flickr $READABLE_DATE" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment