Last active
December 18, 2015 01:29
-
-
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.
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
#!/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