blob: f23debaff440013aaa2e182a479c1fdd9f4d70da (
plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#!/bin/bash
#
# ===========================================================
# Based on script from @Anachron's i3blocks, as well as
# @Addy's icon additions and @Nili's network-connection check
# Mod by @ceeslans, to draw icons from tint2 config folder
# ===========================================================
# Open Weather Map API code, register to http://openweathermap.org to get one :
API_KEY="addb94619729b6651f54d5c9984a45d4"
# Check on http://openweathermap.org/find :
CITY_ID="5277856"
# Select applicable temperature symbol "˚C" or "˚F" :
SYMBOL_CELSIUS="˚F"
# Change "Text" to your preferred language :
TEXT_SNOW="Snow"
TEXT_RAINY="Rainy"
TEXT_DRIZZLE="Drizzle"
TEXT_SHOWERS="Showers"
TEXT_SUNNY="Sunny"
TEXT_CLEAR="Clear"
TEXT_CLOUDY="Cloudy"
TEXT_OVERCAST="Overcast"
TEXT_STORM="Storm"
TEXT_FOG="Fog"
# Show Papirus weather-icons :
ICONPATH="$HOME/.config/tint2/executors/icons/weather/"
# or show original openweathermap weather-icons :
#ICONPATH="$HOME/.config/tint2/executors/icons/weather/openweathermap/"
# Don't change these lines, unless you know what you're doing...
if ping -qc1 1.1.1.1 >/dev/null; then
WEATHER_URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&appid=${API_KEY}&units=imperial"
else
echo "${ICONPATH}404.png"
echo "Link Down"
fi
WEATHER_INFO=$(wget -qO- "${WEATHER_URL}")
WEATHER_MAIN=$(echo "${WEATHER_INFO}" | grep -o -e '\"main\":\"[A-Za-z]*\"' | awk -F ':' '{print $2}' | tr -d '"')
WEATHER_TEMP=$(echo "${WEATHER_INFO}" | grep -o -e '\"temp\":\-\?[0-9]*' | awk -F ':' '{print $2}' | tr -d '"')
WEATHER_ICON=$(echo "${WEATHER_INFO}" | grep -o -e '\"icon\":\"[0-9a-z]*\"' | awk -F ':' '{print $2}' | tr -d '"')
# To add short condition description in the toolbar, comment out # ${TEXT-*} :
if [[ "${WEATHER_MAIN}" = *Snow* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_SNOW}"
elif [[ "${WEATHER_MAIN}" = *Rain* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_RAINY}"
elif [[ "${WEATHER_MAIN}" = *Drizzle* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_DRIZZLE}"
elif [[ "${WEATHER_MAIN}" = *Shower* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_SHOWERS}"
elif [[ "${WEATHER_MAIN}" = *Sunny* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_SUNNY}"
elif [[ "${WEATHER_MAIN}" = *Clear* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_CLEAR}"
elif [[ "${WEATHER_MAIN}" = *Cloud* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_CLOUDY}"
elif [[ "${WEATHER_MAIN}" = *Overcast* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_OVERCAST}"
elif [[ "${WEATHER_MAIN}" = *Storm* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_STORM}"
elif [[ "${WEATHER_MAIN}" = *Fog* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_FOG}"
else
echo "${ICONPATH}04.png"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS} ${WEATHER_MAIN}"
fi
|