Created
February 2, 2010 21:30
-
-
Save Mikoangelo/293054 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# This file is on GitHub as a gist, at http://gist.github.com/293054. | |
WEATHER_STATION = "Glostrup" # Edit this, obviously. | |
begin | |
require 'open-uri' | |
require 'hpricot' | |
rescue LoadError | |
# To ensure the ability to use rubygems without specifying it, while still | |
# avoid stinks. Also, this line rocks. | |
require 'rubygems' and retry or raise | |
end | |
# This could be spruced up with some moon stuff. If your prompt suddenly | |
# starts spewing English at you instead of pretty 8×16 pictograms, add the | |
# relevant missing symbol here. Oh yeah, and add them on GitHub :D | |
Symbols = { | |
"" => "‽", | |
"Fog" => "☕", | |
"Rain" => "☔", | |
"Snow" => "☃", | |
"Clear" => "☉", | |
"Cloudy" => "☁", | |
"Drizzle" => "☂", | |
"Overcast" => "☁", | |
"Heavy Rain" => "☔", | |
"Heavy Snow" => "☃", | |
"Light Rain" => "☂", | |
"Light Snow" => "☃", | |
"Rain Showers" => "☔", | |
"Mostly Sunny" => "☀", | |
"Partly Sunny" => "☼", | |
"Thunderstorm" => "☇", | |
"Mostly Cloudy" => "☁", | |
"Partly Cloudy" => "☁", | |
"Chance of Rain" => "☂", | |
"Freezing drizzle" => "☃" | |
} | |
Symbols.replace Hash[*Symbols.map{ |k,v| [k.downcase, v] }.flatten] | |
destination = $stdout | |
destination = File.open ARGV[0], 'w' if ARGV[0] and File.writable? ARGV[0] | |
begin | |
data = Hpricot open('http://www.google.co.uk/ig/api?weather=' + WEATHER_STATION) | |
weather = data.at('current_conditions/condition')[:data].downcase | |
destination.write Symbols[weather] || weather | |
rescue Exception | |
destination.write "☹" # Sadface is sad ☹ | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment