/latestFlickr.sh
http://github.com/syranez/shell_utils · Shell · 40 lines · 13 code · 11 blank · 16 comment · 0 complexity · 8701e429fe44113094f94dd09872ecf3 MD5 · raw file
- #! /usr/bin/env sh
- #
- # downloads the latest picture of a reddpics subreddit
- #
- # Usage:
- # ./latestRedditpic.sh
- # Uri of the site of which you want to download pictures
- URI="http://api.flickr.com/services/feeds/photos_public.gne"
- # Path to write the latest file
- OUTPUT="/tmp/latest.jpg";
- # retrieves the local uri of the latest picture
- #
- # @outputs local uri of latest picture
- getUriLatestPicture () {
- local latest=$(wget -q "${URI}" -O - | tr ">" "\n" | grep '<link rel="enclosure"' | sed 's/.*href="//g' | sed 's/".*//g' | head -n 1);
- echo "${latest}"
- }
- # gets an image from an uri
- #
- # @param string uri
- # @writes /tmp/latest.jpg
- # @returns wget status
- get () {
- local uri="${1}";
- wget -q "${uri}" -O ${OUTPUT};
- }
- latest=$(getUriLatestPicture);
- get "${latest}";
- exit;