Skip to content

Instantly share code, notes, and snippets.

@northofnormal
Created December 3, 2018 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save northofnormal/95bdf43e898375749b82736387a8f0d7 to your computer and use it in GitHub Desktop.
Save northofnormal/95bdf43e898375749b82736387a8f0d7 to your computer and use it in GitHub Desktop.
Weather Fetching for command line weather emoji
#!/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