Created
January 18, 2012 01:35
-
-
Save rgov/1630236 to your computer and use it in GitHub Desktop.
Fetches a photo from a Flickr group's pool.
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/sh | |
| API_KEY= | |
| API_URL=https://secure.flickr.com/services/rest/ | |
| GROUP_ID=52242140489@N01 | |
| # Fetch the ID of the latest photo added to the group's pool. | |
| PHOTO_ID=$(\ | |
| curl \ | |
| --silent \ | |
| --data-urlencode "method=flickr.groups.pools.getPhotos" \ | |
| --data-urlencode "api_key=${API_KEY}" \ | |
| --data-urlencode "group_id=${GROUP_ID}" \ | |
| --data-urlencode "per_page=1" \ | |
| "${API_URL}" \ | |
| \ | |
| | grep \ | |
| --regexp='<photo\s+' \ | |
| --extended-regexp \ | |
| \ | |
| | grep \ | |
| --regexp='\s+id="[0-9]+"' \ | |
| --extended-regexp \ | |
| --only-matching \ | |
| \ | |
| | cut \ | |
| -d '"' \ | |
| -f 2 \ | |
| ) | |
| # Fetch the largest size available for this photo. | |
| PHOTO_URL=$(\ | |
| curl \ | |
| --silent \ | |
| --data-urlencode "method=flickr.photos.getSizes" \ | |
| --data-urlencode "api_key=${API_KEY}" \ | |
| --data-urlencode "photo_id=${PHOTO_ID}" \ | |
| --data-urlencode "per_page=1" \ | |
| "${API_URL}" \ | |
| \ | |
| | grep \ | |
| --regexp='<size\s+' \ | |
| --extended-regexp \ | |
| \ | |
| | cut \ | |
| -d '"' \ | |
| -f 4,8 \ | |
| \ | |
| | sort \ | |
| --numeric-sort \ | |
| --reverse \ | |
| --field-separator='"' \ | |
| \ | |
| | head \ | |
| -n 1 \ | |
| \ | |
| | cut \ | |
| -d '"' \ | |
| -f 2 \ | |
| ) | |
| echo "${PHOTO_URL}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment