-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinmet.sh
executable file
·86 lines (63 loc) · 1.55 KB
/
inmet.sh
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
#!/usr/bin/env bash
# download satellite images from
# Brazilian National Institute of Meteorology
# <https://satelite.inmet.gov.br/>
# by mountaineerbr ago/2022
# requires curl and jq
# usage: $ inmet.sh 2020-12-15
#choose which image sets to download
URLS=(
https://apisat.inmet.gov.br/GOES/AS/IV #GOES
#https://apisat.inmet.gov.br/GOESIM/BR/CH #GOES+SIMSAT
#https://apisat.inmet.gov.br/MSG/GL/PHPA #GOES+MSG
#https://apisat.inmet.gov.br/SATELITE/AS/P #SATELITE+COSMOS
)
#date
DATE="${1:-$(date -I)}"
#maximum async jobs
JOBMAX=10
#results directory
TEMPD="${TMPDIR:-/tmp}/inmet"
#temp buffers
BUFD="$TEMPD/cache"
cleanf()
{
trap \ INT HUP EXIT
pkill -P $$
wait
[[ -d "$BUFD" ]] && rm -rf "$BUFD"
echo -e "\nresults at -- $TEMPD"
exit
}
trap cleanf INT HUP EXIT
mkdir -pv "$BUFD" || exit
for url in "${URLS[@]}"
do
((m++))
data="$BUFD/data.$m.json"
echo
#json+base64 data
curl -L -o "$data" --compressed "$url/$DATE" || exit
#get ids
IDS=( $(jq -r '.[].id' "$data" ) )
n=0
for i in "${IDS[@]}"
do ((n++))
#asynchronous
{
buf="$BUFD/$m.$n.buffer.json"
jq -r ".[]|select(.id==$i)" "$data" > "$buf"
nome="$(jq -r '"\(.nome)_\(.satelite // "sat")"' "$buf")"
#ext="$( jq -r '.base64' "$buf" | cut -f1 -d\; | cut -f2 -d/ )"
ext=jpg
tgt="$TEMPD/$nome.$ext"
[[ -e "$tgt" ]] || jq -r '.base64' "$buf" | cut -f2 -d, | base64 -di > "$tgt"
} &
echo -ne "url: $m/${#URLS[@]} file: $n/${#IDS[@]} \r"
#bash job control
while jobs=( $(jobs -p) ) ;((${#jobs[@]} > JOBMAX))
do sleep 0.04
done
done
wait
done