Created
September 29, 2014 19:33
-
-
Save DVG/650a2dfa3b49c2637ca2 to your computer and use it in GitHub Desktop.
Update background Image to National Geographic Photo of the day
This file contains 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
TODAY = Time.now.strftime("%Y-%m-%d") | |
USER = "MY_USER" | |
PICTURES_DIR = "/home/#{USER}/Pictures/national-geographic/" | |
TODAYS_PICTURE = "#{PICTURES_DIR}#{TODAY}-ngeo.jpg" | |
PROXY_HOST = 'proxy.example.net' | |
PROXY_PORT = 8443 | |
desc "Fetch National Geographic Photo of the Day" | |
task :get_photo_of_the_day do | |
# http://photography.nationalgeographic.com/photography/photo-of-the-day/ | |
NG_IMAGES_HOSTNAME = "images.nationalgeographic.com" | |
page = "" | |
proxy = Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT) | |
proxy.start("photography.nationalgeographic.com") do |http| | |
page = http.get('/photography/photo-of-the-day/') | |
end | |
image_path = page.body.match(/#{NG_IMAGES_HOSTNAME}(.+\.jpg)/)[1] | |
proxy.start(NG_IMAGES_HOSTNAME) do |http| | |
image = http.get(image_path) | |
File.open(TODAYS_PICTURE, "w") do |file| | |
file.write image.body | |
end | |
end | |
end | |
desc "Update Background Image" | |
task :update_background_image do | |
unless File.exists?(TODAYS_PICTURE) | |
Rake::Task["get_photo_of_the_day"].invoke | |
end | |
system %Q{gsettings set org.gnome.desktop.background picture-uri file://#{TODAYS_PICTURE}} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment