Skip to content

Instantly share code, notes, and snippets.

@evanwalsh
Last active December 17, 2015 04:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanwalsh/5554898 to your computer and use it in GitHub Desktop.
Save evanwalsh/5554898 to your computer and use it in GitHub Desktop.
Forecast.io script for GeekTool
#!/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