-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather
More file actions
executable file
·51 lines (42 loc) · 1.82 KB
/
weather
File metadata and controls
executable file
·51 lines (42 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# I take this script from Anachron's i3blocks
# I only slightly modify this script to add an option to show icon
# I also remove the i3blocks specify script
# To make this works with tint2 executor, polybar custom script, dzen2 feeder, conkybar, lemonbar feeder, dunst notify, etc.
# 'weather -i' = with icon, 'weather' = text only
# Cheers!
# Addy
# Open Weather Map API code, register to http://openweathermap.org to get one ;)
API_KEY="214cc439c224157ccdac5a8ed6d058e7"
# Check on http://openweathermap.org/find
CITY_ID="2778067"
ICON_SUNNY=" Clear"
ICON_CLOUDY=" Cloudy"
ICON_RAINY=" Rainy"
ICON_STORM=" Storm"
ICON_SNOW=" Snow"
ICON_FOG=" Fog"
ICON_MISC=" "
TEXT_SUNNY="Clear"
TEXT_CLOUDY="Cloudy"
TEXT_RAINY="Rainy"
TEXT_STORM="Storm"
TEXT_SNOW="Snow"
TEXT_FOG="Fog"
SYMBOL_CELSIUS="˚C"
WEATHER_URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&appid=${API_KEY}&units=metric"
WEATHER_INFO=$(wget -qO- "${WEATHER_URL}")
WEATHER_MAIN=$(echo "${WEATHER_INFO}" | grep -o -e '\"main\":\"[a-Z]*\"' | awk -F ':' '{print $2}' | tr -d '"')
WEATHER_TEMP=$(echo "${WEATHER_INFO}" | grep -o -e '\"temp\":\-\?[0-9]*' | awk -F ':' '{print $2}' | tr -d '"')
if [[ "${WEATHER_MAIN}" = *Snow* ]]; then
echo "${ICON_SNOW} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
elif [[ "${WEATHER_MAIN}" = *Rain* ]] || [[ "${WEATHER_MAIN}" = *Drizzle* ]]; then
echo "${ICON_RAINY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
elif [[ "${WEATHER_MAIN}" = *Cloud* ]]; then
echo "${ICON_CLOUDY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
elif [[ "${WEATHER_MAIN}" = *Clear* ]]; then
echo "${ICON_SUNNY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
elif [[ "${WEATHER_MAIN}" = *Fog* ]] || [[ "${WEATHER_MAIN}" = *Mist* ]]; then
echo "${ICON_FOG} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
else
echo "${ICON_MISC} ${WEATHER_MAIN} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
fi