-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather
executable file
·117 lines (105 loc) · 2.67 KB
/
weather
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Required Optional Optional
# Use: weather <location> <units> <timeFormat>
# Importing preferences from Prefs.cfg #
source Prefs.cfg
# First parameter after command #
location=$(echo $1 | sed 's/\-/%20/g')
for i in {2..6}
do
eval temp='$'$i
if [[ ! -z $temp ]]
then
case $temp in
"-12")
timeFormat="12"
;;
"-24")
timeFormat="24"
;;
"-s")
singleEvent="y"
;;
"-nC")
clearTerminal="n"
;;
"-nI")
displayWeatherImage="n"
;;
"-i")
units="imperial"
;;
"-m")
units="metric"
esac
fi
done
# Operation tha clear the terminal, enabled by default, can be disabled easily using ./UpdatePrefs.sh
if [[ "$clearTerminal" == "y" ]]
then
clear
fi
echo -e '\e[1A'
# Time format selection #
if [[ "$timeFormat" == "12" ]]
then
timeFormat="+%I:%M:%S"
else
timeFormat="+%H:%M:%S"
fi
# Units of measurement selection #
if [[ "$units" == "imperial" ]]
then
unitTemp="F"
unitWind="mph"
else
unitTemp="C"
unitWind="m/s"
fi
cat $installLocation'/Banner.txt'
# Main loop that display data accordingly to Prefs.cfg
while :
do
read weather temp tempFeel tempMin tempMax humidity sunrise sunset < <(echo $(curl -s --request GET --url 'api.openweathermap.org/data/2.5/weather?q='$location'&appid='$apiKey'&units='$units | jq '.weather[].main, .main.temp, .main.feels_like, .main.temp_min, .main.temp_max, .main.humidity, .sys.sunrise, .sys.sunset' ))
if [[ "$displayWeatherImage" == "y" ]]
then
weather=$(echo $weather | tr -d '"')
displayWeatherImage="n"
case $weather in
"Clear")
sed -n 10,16p $installLocation'/WeatherImages.txt'
;;
"Clouds")
sed -n 18,24p $installLocation'/WeatherImages.txt'
;;
"Rain")
sed -n 26,32p $installLocation'/WeatherImages.txt'
;;
"Drizzle")
sed -n 34,40p $installLocation'/WeatherImages.txt'
;;
"Thunderstorm")
sed -n 42,48p $installLocation'/WeatherImages.txt'
;;
"Snow")
sed -n 50,56p $installLocation'/WeatherImages.txt'
;;
"Atmosphere")
sed -n 58,64p $installLocation'/WeatherImages.txt'
;;
esac
fi
echo "The temperature is ${temp}${unitTemp}, but it feels like ${tempFeel}${unitTemp}"
echo "The humidity is at ${humidity}%"
echo "Min: ${tempMin}${unitTemp} | Max: ${tempMax}${unitTemp}"
echo -e "The sun will rise at "$(date -d @${sunrise} ${timeFormat})" and set at "$(date -d @${sunset} ${timeFormat})
# If user choose to not update every n seconds, while loop will be broken. This feature is disabled by default, but editable using ./UpdatePrefs.sh
if [[ "$singleEvent" == "y" ]]
then
break
fi
# Refresh data timer #
sleep $refreshTime
# Clear every line before updating stats #
echo -e '\e[5A'
done