Skip to content

Instantly share code, notes, and snippets.

@evan-goode
Created February 10, 2016 03:30
Show Gist options
  • Save evan-goode/5861ee2ca32e890d304c to your computer and use it in GitHub Desktop.
Save evan-goode/5861ee2ca32e890d304c to your computer and use it in GitHub Desktop.
returns an emoji representing the current weather conditions in a specified location
#!/bin/bash
woeid="2390183"
weather=`curl --silent "http://xml.weather.yahoo.com/forecastrss?w=${woeid}&u=f" | xmllint --xpath "string(//*[local-name()='condition']//@code)" -`
# codes from https://developer.yahoo.com/weather/documentation.html#codes
case "$weather" in
0) # tornado
emoji="🌪" # cloud with tornado
;;
1|2|23|24) # tropical storm, hurricane, blustery, windy
emoji="💨" # dash symbol
;;
3|4|37|38|39|45|47) # severe thunderstorms, thunderstorms, isolated thunderstorms, scattered thunderstorms, scattered thunderstorms, thundershowers, isolated thundershowers
emoji="⛈" # thunder cloud and rain
;;
5|7|13|14|15|16|17|41|42|43|46) # mixed rain and snow, mixed snow and sleet, snow flurries, light snow showers, blowing snow, snow, hail, heavy snow, scattered snow showers, heavy snow, snow showers
emoji="🌨" # cloud with snow
;;
6|8|9|10|11|12|18|35|40) # mixed rain and sleet, freezing drizzle, drizzle, freezing rain, showers, showers, sleet, mixed rain and hail, scattered showers
emoji="🌧" # cloud with rain
;;
19|20|21|22) # dust, foggy, haze, smoky
emoji="🌫" # fog
;;
25) # cold
emoji="❄️" # snowflake
;;
26|27|29) # cloudy, mostly cloudy (night), partly cloudy (night)
emoji="☁️" # cloud
;;
28) # mostly cloudy (day)
emoji="🌥" # white sun behind cloud
;;
30|44) # partly cloudy (day), partly cloudy
emoji="⛅️" # sun behind cloud
;;
31|33) # clear (night), fair (night)
emoji="🌙" # crescent moon
;;
32|36) # sunny, hot
emoji="☀️" # black sun with rays
;;
34) # fair (sunny)
emoji="🌤" # white sun with small cloud
;;
*)
exit 1
;;
esac
echo $emoji
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment