-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_weather.sh
executable file
·35 lines (30 loc) · 1.03 KB
/
.bash_weather.sh
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
#!/bin/b
dlWeather (){
local URL="http://api.openweathermap.org/data/2.5/weather?q=Moscow,ru&appid=7eed88250f409f8e0c3320ce28689171&units=metric&mode=json"
local RESPONSEHOLDER=$(curl -s $URL)
local TEMP=$(echo "$RESPONSEHOLDER" | grep -o -e '"temp":[-0-9.]*' | cut -d ':' -f2)
local WEATHERCODE=$(echo "$RESPONSEHOLDER" | grep -o -e '"main":"[a-zA-Z]*' | cut -d '"' -f4)
echo "$TEMP""º $WEATHERCODE"
}
getWeather (){
local u=600
local NOW=$(date +%s)
CONFIGFILE=/Users/semenov/.LAST_TIME_CHECKED_WEATHER.vars
if [ -r ${CONFIGFILE} ]; then
# Read the configfile if it's existing and readable
source ${CONFIGFILE}
fi
# if [ -z "$LAST_TIME_CHECKED_WEATHER" ] || [ "$LAST_TIME_CHECKED_WEATHER" -lt $((NOW - u)) ] ; then
echo -n ""> ${CONFIGFILE}
# wget -q --spider http://google.com
# if [ $? -eq 0 ]; then
WEATHERCHAR=$(dlWeather)
echo WEATHERCHAR="\"$WEATHERCHAR\"">> ${CONFIGFILE}
# else
# echo WEATHERCHAR='---'>> ${CONFIGFILE}
# fi
# echo LAST_TIME_CHECKED_WEATHER=$NOW>> ${CONFIGFILE}
# fi
# echo "$WEATHERCHAR"
}
getWeather