Skip to content

Instantly share code, notes, and snippets.

@ylluminate
Forked from jah2488/image.md
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ylluminate/df7167fab39538e4c4cf to your computer and use it in GitHub Desktop.
Save ylluminate/df7167fab39538e4c4cf to your computer and use it in GitHub Desktop.
require 'opal-jquery'
gui = `require('nw.gui')`
tray = `new gui.Tray({ title: 'weather', icon: 'sunny.gif', tooltip: 'weather loading' })`
def kelvin_to_fahrenheit(temp)
((temp - 273.15) * 1.8 + 32.0).round(1)
end
def icon(type)
case type.downcase
when /rain/ then 'rain.png'
when /cloud/ then 'cloudy.png'
when /sun/ then 'sunny.gif'
else
''
end
end
FIVE_MINS = 300000
def get_weather
HTTP.get('http://api.openweathermap.org/data/2.5/weather?zip=78704,us') do |response|
json = response.json
title = kelvin_to_fahrenheit(json['main']['temp'])
icon = icon(json['weather'][0]['main'])
`tray.title = #{title} + 'F'`
`tray.icon = #{icon}`
end
end
get_weather
%x{ setInterval(function () { #{ get_weather } }, #{FIVE_MINS}); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment