/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. # Uri of the site of which you want to download pictures
  8. URI="http://api.flickr.com/services/feeds/photos_public.gne"
  9. # Path to write the latest file
  10. OUTPUT="/tmp/latest.jpg";
  11. # retrieves the local uri of the latest picture
  12. #
  13. # @outputs local uri of latest picture
  14. getUriLatestPicture () {
  15. local latest=$(wget -q "${URI}" -O - | tr ">" "\n" | grep '<link rel="enclosure"' | sed 's/.*href="//g' | sed 's/".*//g' | head -n 1);
  16. echo "${latest}"
  17. }
  18. # gets an image from an uri
  19. #
  20. # @param string uri
  21. # @writes /tmp/latest.jpg
  22. # @returns wget status
  23. get () {
  24. local uri="${1}";
  25. wget -q "${uri}" -O ${OUTPUT};
  26. }
  27. latest=$(getUriLatestPicture);
  28. get "${latest}";
  29. exit;