Add covid and weather scripts for zsh segments

This commit is contained in:
Alex D. 2020-11-06 17:54:06 +01:00
parent 552ae9cfd0
commit c83062edce
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 18 additions and 0 deletions

5
fetch-covid.zsh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/zsh
([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return
typeset -g _cprompts_covid=($(curl -sL https://api.covid19api.com/country/${1:-germany} | jq -e '. |= sort_by (.Date) | .[-1,-2].Active'))
[ ! -z $_cprompts_covid[1] ] && <<< ${_cprompts_covid} > ${2:-~/.cache/covid}

13
fetch-weather.zsh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/zsh
([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return
zmodload zsh/mathfunc
typeset -A icons
typeset -A colors
icons=([c]='' [lc]='' [hc]='' [s]='🌢' [lr]='🌢' [hr]='' [sn]='' [t]='' [h]='' [sl]='')
colors=([c]="yellow" [lc]="yellow" [hc]="cyan" [s]="yellow" [lr]="cyan" [hr]="blue" [t]="white" [h]="white" [sl]="blue" [sn]="white")
result=$(curl -sL https://www.metaweather.com/api/location/${1:-1339615}/ | jq -e '.consolidated_weather[0] | {"temp": .the_temp, "hum": .humidity, "icon": .weather_state_abbr}')
if [ ! -z $result ]; then
ico=$(<<< "$result" jq -r '.icon')
<<< "$(( int(rint($(jq -r '.temp' <<< $result))) )) ${colors[$ico]:-white} ${icons[$ico]:-X} $(( int(rint($(jq -r '.hum' <<< $result))) ))" > ${2:-~/.cache/weather}
fi