Skip to content

Instantly share code, notes, and snippets.

@michels
Last active June 8, 2021 21:32
Show Gist options
  • Save michels/90327b8d284646a238e6 to your computer and use it in GitHub Desktop.
Save michels/90327b8d284646a238e6 to your computer and use it in GitHub Desktop.
Uses the OpenWeatherMap to get an emoji based on the current weather // OpenWeaterMap emoji matcher in ruby.
OPENWEATHER_APIKEY = "" # TODO add your apikey here
lat = "49.868183" # latitude of the city you want to get the weather from
lon = "8.626288499" # longitude of the city you want to get the weather from
def getWeatherEmoji(weatherID)
# Openweathermap Weather codes and corressponding emojis
thunderstorm = "\u{1F4A8}" # Code: 200's, 900, 901, 902, 905
drizzle = "\u{1F4A7}" # Code: 300's
rain = "\u{02614}" # Code: 500's
snowflake = "\u{02744}" # Code: 600's snowflake
snowman = "\u{026C4}" # Code: 600's snowman, 903, 906
atmosphere = "\u{1F301}" # Code: 700's foogy
clearSky = "\u{02600}" # Code: 800 clear sky
fewClouds = "\u{026C5}" # Code: 801 sun behind clouds
clouds = "\u{02601}" # Code: 802-803-804 clouds general
hot = "\u{1F525}" # Code: 904
defaultEmoji = "\u{1F300}" # default emojis
if (weatherID = weatherID.to_s)
if weatherID.chars.first == '2' or weatherID == '900' or weatherID == '901' or weatherID == '902' or weatherID == '905'
return thunderstorm
elsif weatherID.chars.first == '3'
return drizzle
elsif weatherID.chars.first == '5'
return rain
elsif weatherID.chars.first == '6' or weatherID == '903' or weatherID == '906'
return snowflake + ' ' + snowman
elsif weatherID.chars.first == '7'
return atmosphere
elsif weatherID == '800'
return clearSky
elsif weatherID == '801'
return fewClouds
elsif weatherID == '802' or weatherID == '803' or weatherID == '803'
return clouds
elsif weatherID == '904'
return hot
else
return defaultEmoji
end
else
return defaultEmoji
end
end
weatherUrl = "http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+lon+"&appid="+OPENWEATHER_APIKEY
weather = HTTParty.get(weatherUrl)
puts weather['weather'][0]['description'] + ' ' + getWeatherEmoji(weather['weather'][0]['id'])
@eggplants
Copy link

sed -i "s/803'\$/804'/" openweather_emoji.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment