Created
December 3, 2018 14:42
-
-
Save northofnormal/95bdf43e898375749b82736387a8f0d7 to your computer and use it in GitHub Desktop.
Weather Fetching for command line weather emoji
This file contains 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/ruby | |
# Next steps: | |
# refresh periodically? | |
# update location from command line? | |
require 'open-uri' | |
require 'json' | |
state = ARGV[0] | |
city = ARGV[1] | |
state = "MI" unless state | |
city = "Detroit" unless city | |
formattedURL = "http://api.wunderground.com/api/b193c8afeeecdbb2/geolookup/conditions/q/#{state}/#{city}.json" | |
open(formattedURL) do |f| | |
json_string = f.read | |
parsed_json = JSON.parse(json_string) | |
weather = parsed_json['current_observation']['weather'] | |
weatherEmoji = "🍆" | |
if weather["Clear"] | |
weatherEmoji = "☀️" | |
elsif weather["Drizzle"] || weather["Rain"] | |
weatherEmoji = "☔️" | |
elsif weather["Thunder"] | |
weatherEmoji = "⚡️" | |
elsif weather["Snow"] | |
weatherEmoji = "❄️" | |
elsif weather["Partly Cloudy"] | |
weatherEmoji = "⛅️" | |
elsif weather["Clouds"] || weather["Cloudy"] || weather["Fog"] || weather["Overcast"] | |
weatherEmoji = "☁️" | |
end | |
puts "#{weatherEmoji} " | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment