mirror of
https://github.com/lordmathis/dotfiles.git
synced 2025-11-06 01:34:22 +00:00
Add scripts
This commit is contained in:
52
bin/openweathermap-simple.sh
Executable file
52
bin/openweathermap-simple.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
|
||||
get_icon() {
|
||||
case $1 in
|
||||
01d) icon="";;
|
||||
01n) icon="";;
|
||||
02d) icon="";;
|
||||
02n) icon="";;
|
||||
03*) icon="";;
|
||||
04*) icon="";;
|
||||
09d) icon="";;
|
||||
09n) icon="";;
|
||||
10d) icon="";;
|
||||
10n) icon="";;
|
||||
11d) icon="";;
|
||||
11n) icon="";;
|
||||
13d) icon="";;
|
||||
13n) icon="";;
|
||||
50d) icon="";;
|
||||
50n) icon="";;
|
||||
*) icon="";
|
||||
esac
|
||||
|
||||
echo $icon
|
||||
}
|
||||
|
||||
KEY="55d35ce697a99136aab82ea73edcb538"
|
||||
CITY=""
|
||||
UNITS="metric"
|
||||
SYMBOL="°"
|
||||
|
||||
if [ ! -z $CITY ]; then
|
||||
weather=$(curl -sf "http://api.openweathermap.org/data/2.5/weather?APPID=$KEY&id=$CITY&units=$UNITS")
|
||||
# weather=$(curl -sf "http://api.openweathermap.org/data/2.5/forecast?APPID=$KEY&id=$CITY&units=$UNITS&cnt=1")
|
||||
else
|
||||
location=$(curl -sf https://location.services.mozilla.com/v1/geolocate?key=geoclue)
|
||||
|
||||
if [ ! -z "$location" ]; then
|
||||
location_lat="$(echo "$location" | jq '.location.lat')"
|
||||
location_lon="$(echo "$location" | jq '.location.lng')"
|
||||
|
||||
weather=$(curl -sf "http://api.openweathermap.org/data/2.5/weather?appid=$KEY&lat=$location_lat&lon=$location_lon&units=$UNITS")
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -z "$weather" ]; then
|
||||
weather_temp=$(echo "$weather" | jq ".main.temp" | cut -d "." -f 1)
|
||||
weather_icon=$(echo "$weather" | jq -r ".weather[].icon")
|
||||
|
||||
echo "$(get_icon "$weather_icon")" "$weather_temp$SYMBOL"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user