Skip to content

Instantly share code, notes, and snippets.

@jah2488
Last active April 16, 2021 16:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jah2488/4ec250d916676d1daf62 to your computer and use it in GitHub Desktop.
Save jah2488/4ec250d916676d1daf62 to your computer and use it in GitHub Desktop.
Creates a Menubar application using Node Webkit and Opal

A tiny app using opal.rb and nodewebkit to get your weather in your toolbar. so small

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