Advertisement
msjche

natgeo.sh

Jun 30th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. #!/bin/bash
  2. # Copyright (c) 2011 Josh Schreuder
  3. # http://www.postteenageliving.com
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. # THE SOFTWARE.
  22. # ********************************
  23. # *** OPTIONS
  24. # ********************************
  25. # Set this to 'yes' to save a description (to ~/description.txt) from ngeo page
  26. GET_DESCRIPTION="yes"
  27. # Set this to the directory you want pictures saved
  28. PICTURES_DIR=~/Pictures
  29. # ********************************
  30. # *** FUNCTIONS
  31. # ********************************
  32. function get_page {
  33. echo "Downloading page to find image"
  34. wget http://photography.nationalgeographic.com/photography/photo-of-the-day/ --quiet -O- 2> /dev/null |
  35. grep -m 1 http://images.nationalgeographic.com/.*.jpg -o > /tmp/pic_url
  36. }
  37. function clean_up {
  38. # Clean up
  39. echo "Cleaning up temporary files"
  40. if [ -e "/tmp/pic_url" ]; then
  41. rm /tmp/pic_url
  42. fi
  43. }
  44. # ********************************
  45. # *** MAIN
  46. # ********************************
  47. echo "===================="
  48. echo "== NGEO Wallpaper =="
  49. echo "===================="
  50. # Set date
  51. TODAY=$(date +'%Y%m%d')
  52. # If we don't have the image already today
  53. if [ ! -e ~/Pictures/${TODAY}_ngeo.jpg ]; then
  54. echo "We don't have the picture saved, save it"
  55. get_page
  56. # Got the link to the image
  57. PICURL=`/bin/cat /tmp/pic_url`
  58. echo "Picture URL is: ${PICURL}"
  59. echo "Downloading image"
  60. wget --quiet $PICURL -O $PICTURES_DIR/${TODAY}_ngeo.jpg
  61. feh $PICTURES_DIR/${TODAY}_ngeo.jpg
  62. # Else if we have it already, check if it's the most updated copy
  63. else
  64. get_page
  65. # Got the link to the image
  66. PICURL=`/bin/cat /tmp/pic_url`
  67. echo "Picture URL is: ${PICURL}"
  68. # Get the filesize
  69. SITEFILESIZE=$(wget --spider $PICURL 2>&1 | grep Length | awk '{print $2}')
  70. FILEFILESIZE=$(stat -c %s $PICTURES_DIR/${TODAY}_ngeo.jpg)
  71. # If the picture has been updated
  72. if [ $SITEFILESIZE != $FILEFILESIZE ]; then
  73. echo "The picture has been updated, getting updated copy"
  74. rm $PICTURES_DIR/${TODAY}_ngeo.jpg
  75. # Got the link to the image
  76. PICURL=`/bin/cat /tmp/pic_url`
  77. echo "Downloading image"
  78. wget --quiet $PICURL -O $PICTURES_DIR/${TODAY}_ngeo.jpg
  79. echo "Here it is: "
  80. feh $PICTURES_DIR/${TODAY}_ngeo.jpg
  81. # If the picture is the same
  82. else
  83. echo "Picture is the same, finishing up"
  84. echo "Here it is: "
  85. feh $PICTURES_DIR/${TODAY}_ngeo.jpg
  86. fi
  87. fi
  88. clean_up
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement