Last active
August 10, 2022 03:12
-
-
Save bencollerson/cfd58fe5758720040f2e2b321f8c545b to your computer and use it in GitHub Desktop.
openweathermap minimalist bash script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
location=sydney | |
units=metric # or "imperial" (or even "standard" if you like using kelvin for temperature) | |
appid= #put your openweathermap id here | |
weather_curl=$(curl -sf "https://api.openweathermap.org/data/2.5/weather?q=$location&units=$units&appid=$appid") | |
currenttime=$(date +%s) | |
temperature=$(echo $weather_curl | jq .main.temp) | |
temperature=$(printf "%.0f\U00B0" $temperature) | |
sunrise=$(echo $weather_curl | jq .sys.sunrise) | |
sunset=$(echo $weather_curl | jq .sys.sunset) | |
weathercode=$(echo $weather_curl | jq .weather[0].id) | |
case $weathercode in | |
2[0-9][0-9] ) # thunderstorm | |
emoji=$(printf "\U26C8") | |
;; | |
3[0-9][0-9] ) # drizzle | |
emoji=$(printf "\U1F326") | |
;; | |
5[0-9][0-9] ) # rain | |
emoji=$(printf "\U1F327") | |
;; | |
6[0-9][0-9] ) #snow | |
emoji=$(printf "\U1F328") | |
;; | |
781 ) # cyclone | |
emoji=$(printf "\U1F300") | |
;; | |
7[0-9][0-9] ) # fog | |
emoji=$(printf "\U1F32B") | |
;; | |
800 ) # clear | |
if [ $currenttime -ge $sunrise ] && [ $currenttime -lt $sunset ]; then | |
emoji=$(printf "\U1F31E") | |
else | |
emoji=$(printf "\U1F319") | |
fi | |
;; | |
801 ) # few clouds | |
emoji=$(printf "\U1F324") | |
;; | |
8[0-9][0-9] ) # clouds | |
emoji=$(printf "\U1F325") | |
;; | |
* ) # default | |
emoji=$(printf "\U1FA90") | |
;; | |
esac | |
echo ${emoji}${temperature} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment