A tiny app using opal.rb and nodewebkit to get your weather in your toolbar.
Last active
April 16, 2021 16:49
-
-
Save jah2488/4ec250d916676d1daf62 to your computer and use it in GitHub Desktop.
Creates a Menubar application using Node Webkit and Opal
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