Skip to content

Instantly share code, notes, and snippets.

@PogiNate
Last active June 27, 2017 18:41
Show Gist options
  • Save PogiNate/4cf62cf37023249333e00c0a06c0cc1c to your computer and use it in GitHub Desktop.
Save PogiNate/4cf62cf37023249333e00c0a06c0cc1c to your computer and use it in GitHub Desktop.
Create a one line file with weather info in it. Created as an example for Painless Tmux, updated to be worth using. The Emoji works best on MacOS
#! /usr/bin/env ruby
require 'json'
require 'open-uri'
@api_key = "YOUR_API_KEY"
@lat = "40.520882"
@long= "-111.962284"
forecast = JSON.parse(open("https://api.darksky.net/forecast/#{@api_key}/#{@lat},#{@long}").read)
temp = forecast['currently']['temperature']
icon_text = forecast['currently']['icon']
icon =
case icon_text
when 'clear-day'
'☀️'
when 'clear-night'
'🌕'
when 'rain'
'🌧'
when 'snow'
'❄️'
when 'sleet'
'🌨'
when 'wind'
'💨'
when 'fog'
'🌫'
when 'cloudy'
'☁️'
when 'partly-cloudy-day'
'🌤'
when 'partly-cloudy-night'
'🌥' #I need a better emoji for partly cloudy night.
else
'🙃'
end
File.open('/tmp/weather.txt', 'w'){|file| file.write("#{icon} #{temp.to_i}° ")}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment