PageRenderTime 12ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/latestFlickr.sh

http://github.com/syranez/shell_utils
Shell | 40 lines | 13 code | 11 blank | 16 comment | 0 complexity | 8701e429fe44113094f94dd09872ecf3 MD5 | raw file
 1#! /usr/bin/env sh
 2#
 3# downloads the latest picture of a reddpics subreddit
 4#
 5# Usage:
 6#   ./latestRedditpic.sh
 7
 8# Uri of the site of which you want to download pictures
 9URI="http://api.flickr.com/services/feeds/photos_public.gne"
10
11# Path to write the latest file
12OUTPUT="/tmp/latest.jpg";
13
14# retrieves the local uri of the latest picture
15#
16# @outputs local uri of latest picture
17getUriLatestPicture () {
18
19    local latest=$(wget -q "${URI}" -O - | tr ">" "\n" | grep '<link rel="enclosure"' | sed 's/.*href="//g' | sed 's/".*//g' | head -n 1);
20
21    echo "${latest}"
22}
23
24# gets an image from an uri
25#
26# @param string uri
27# @writes /tmp/latest.jpg
28# @returns wget status
29get () {
30
31    local uri="${1}";
32
33    wget -q "${uri}" -O ${OUTPUT};
34}
35
36latest=$(getUriLatestPicture);
37
38get "${latest}";
39
40exit;