Created
October 21, 2012 08:55
-
-
Save pimeys/3926413 to your computer and use it in GitHub Desktop.
Weather information for Xmobar
This file contains hidden or 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
# encoding: utf-8 | |
require 'json' | |
require 'net/http' | |
def styled_temp(temp) | |
if temp < 15.0 | |
"<fc=#AAC0FF>#{temp}</fc>" | |
elsif temp < 20.0 | |
"<fc=#FFFF00>#{temp}</fc>" | |
else | |
"<fc=#FF0000>#{temp}</fc>" | |
end | |
end | |
begin | |
uri = URI('http://weather.yahooapis.com/forecastjson?w=638242&u=c') | |
info = JSON.parse(Net::HTTP.get(uri)) | |
temp_today = styled_temp(info["condition"]["temperature"]) | |
cond_today = info["condition"]["text"].downcase | |
temp_next = styled_temp(info["forecast"].first["high_temperature"]) | |
cond_next = info["forecast"].first["condition"].downcase | |
temp_tomorrow = styled_temp(info["forecast"].last["high_temperature"]) | |
cond_tomorrow = info["forecast"].last["condition"].downcase | |
puts "#{cond_today} #{temp_today} (f: #{temp_next}, #{cond_tomorrow} #{temp_tomorrow})" | |
rescue | |
puts "N/A" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment