Skip to content

Instantly share code, notes, and snippets.

@appplemac
Last active December 18, 2015 01:29
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 appplemac/5704260 to your computer and use it in GitHub Desktop.
Save appplemac/5704260 to your computer and use it in GitHub Desktop.
Quick and dirty script for getting current weather in text mode with Forecast.io API.
#!/usr/bin/env ruby
# encoding: utf-8
require 'forecast_io'
Forecast::IO.api_key = "your_forecast.io_api_key"
# Position for Campus Nord UPC
weather = Forecast::IO.forecast(41.387885, 2.112808, time: Time.now.to_i, params: { units: 'si' })
current = weather[:currently]
temp = current[:temperature]
precip = current[:precipIntensity]
cond = current[:icon].split("-")[0...-1]
print temp, "°C,"
cond.each {|elem| print " ", elem.to_s}
if (cond.first != "clear")
print ", ", precip, " mm precip"
end
print "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment