-
-
Save ylluminate/df7167fab39538e4c4cf 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
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