Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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