This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
corona
executable file
·87 lines (75 loc) · 2.25 KB
/
corona
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
#!/bin/bash
# A wrapper around https://github.com/sagarkarira/coronavirus-tracker-cli
CACHED_FILE="/home/alex/.cache/corona_status.txt"
FEW_COUNTRIES="USA|Canada|China"
ONELINE_COUNTRY="Canada"
usage() {
echo "Usage: $0 (''|download|full|few|help|oneline|[country]|update)"
echo " help : show this message
download: get fresh data
full : pretty print downloaded data
few : pretty print few countries
'' : minimal print few countries with emoji
oneline : minimal print country $ONELINE_COUNTRY
[country]: minimal print oneline of [country]
update : update awesome wibar
few countries are hardcoded as $FEW_COUNTRIES" >&2
exit 0
}
download() {
if curl -s 'https://corona-stats.online' > $CACHED_FILE; then
echo "Cache updated."
notify-send "😷 Corona" "Cache updated."
else
echo "Failed to curl"
exit 1
fi
}
check_freshness() {
# check if the data of the cached file is same as today
if [ "$(stat -c %y $CACHED_FILE 2>/dev/null | cut -d' ' -f1)" != "$(date "+%Y-%m-%d")" ]; then
download || echo "Failed to update cache."
fi
}
print_full() {
cat $CACHED_FILE
}
print_full_minimal() {
print_full |
sed -e '/║/!d' \
-e 's/\x1b\[[0-9;]*m//g' \
-e 's/\s*//g' \
-e 's/║//g' \
-e 's/│/;/g' \
-e 's/([[:upper:]]*)//g' \
-e '1d' |
awk -F';' '{print $2 " 😷" $3"("$4")" " 💀" $5"("$6")"}'
}
# pretty print few countries
print_few() {
rg --no-line-number -e "World" -e $FEW_COUNTRIES $CACHED_FILE
}
# minimal print few countries
print_few_minimal() {
print_full_minimal | rg --no-line-number -e $FEW_COUNTRIES
}
# minimal print one country
# but it may produce multiple lines given partial name
print_minimal_oneline() {
print_full_minimal | rg --ignore-case $ONELINE_COUNTRY
}
update_awesome() {
oneline=$(print_minimal_oneline)
echo "mycorona.text = \"$oneline\"" | awesome-client
}
case "$1" in
h|-h|--help) usage;;
d|download) download;;
full) print_full;;
few) print_few;;
update) update_awesome;;
'') print_few_minimal;;
oneline) print_minimal_oneline;;
*) ONELINE_COUNTRY="$1" ; print_minimal_oneline;;
# *) usage;;
esac