Last active
June 27, 2017 18:41
-
-
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
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 | |
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