Last active
December 17, 2015 04:59
-
-
Save evanwalsh/5554898 to your computer and use it in GitHub Desktop.
Forecast.io script for GeekTool
This file contains hidden or 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 | |
# Get an API key from https://developer.forecast.io/ | |
# | |
# Outputs something like this: | |
# | |
# Clear, 65°F | |
# Moderate chance of rain until tonight | |
FORECAST_IO_API_KEY = "YOUR KEY GOES HERE" | |
LOCATION = "" | |
begin | |
require 'darksky' | |
require 'geocoder' | |
require 'net/http' | |
require 'uri' | |
rescue LoadError => e | |
puts "You need to install the darksky and geocoder gems. Soz." | |
end | |
darksky = Darksky::API.new(FORECAST_IO_API_KEY) | |
location = LOCATION.empty? ? Net::HTTP.get(URI.parse("http://icanhazip.com")).gsub("\n", "") : LOCATION | |
geo = Geocoder.search(location).first | |
forecast = darksky.brief_forecast(geo.latitude, geo.longitude) | |
puts "#{forecast["currentSummary"].capitalize}, #{forecast["currentTemp"]}\u00B0F\n#{forecast["daySummary"].capitalize}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment