A little script I made that fits in my desktop workflow
#!/usr/bin/ruby
require 'rubygems'
require 'json'
require 'etc'
require 'net/http'
require 'fileutils'
require 'configparser'
class Weather
def initialize(location, link)
@location = location
@link = link
@data = get_data
end
def kelvin_to_celcius(kelvin)
((kelvin - 273.15) * 1).round.to_s
end
def get_data
uri = URI(@link + @location)
Net::HTTP.get(uri)
end
def get_degrees
json = JSON.parse( @data )
kelvin_to_celcius(json["main"]["temp_min"].to_i)
end
def to_s
get_degrees + "°C In " + @location
end
end
conf_dir = '/home/' + ENV['USER'] + '/.weatherdzen/'
unless File.exists? conf_dir
FileUtils.mkpath conf_dir
FileUtils.touch conf_dir + 'config'
File.open(conf_dir + 'config', "w") do |f|
f.puts('[basic]')
f.puts('location=Antwerp')
f.puts('notify=notifysend')
f.close
end
end
cfg = ConfigParser.new(conf_dir + 'config')
weather = Weather.new(
cfg["basic"]["location"],
"http://api.openweathermap.org/data/2.5/weather?q="
)
notifier = cfg["basic"]["notify"]
wtr = weather.to_s
if notifier == "dzen"
exec 'echo ' + wtr + '| dzen2 -title-name "brightness" -l 3 -bg "#263238" -fg "#b1fff8" -x 790 -y 480 -w 270 -h 70 -p 3 -e'
elsif notifier == "notifysend"
exec 'notify-send "' + wtr + '"'
end
Needs etc and configparser gems + dzen2 installed.
EDIT:autowrite config, autowrite based on users location coming later
EDIT2: for people with xfce and unity and any other DE that uses notify-send you can now use that and configure in the config file