-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetcsvfilefrompota
49 lines (39 loc) · 1.44 KB
/
getcsvfilefrompota
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
#!/usr/bin/env -S bash -l
if [ -z "$1" ]; then
echo usage `basename $0` country_prefix or country name >&2
exit 0
fi
if [ ! `which jq` ]; then
echo jq must be installed to use this utility >&2
exit 1
fi
# the urlfile api ends in K - for the United States
# for Canada the prefix is VE
# for England the prefix is G
# for Mexico it is XE
PARKPREFIX=$(pcc1 $1 | fzf | cut -d' ' -f1)
csvfile=$(mktemp --suffix=.csv)
tempjsonfile=$(mktemp --suffix=.json)
urlfile=https://api.pota.app/program/parks/${PARKPREFIX}
#
# to get specific state: https://api.pota.app/location/parks/US-MS
#
#curl -s $urlfile | jq --arg cs "$cs" '.[] | select(.activeCallsign == $cs) | ("activations:", .activations, "unique:", .units, "qsos:", .TotalContacts)' >> $file
#column -o' ' -c120 $file | tr -d '"'
# {
# "reference": "K-9999",
# "name": "Coyote Springs State Fish and Wildlife Area",
# "latitude": 45.8426,
# "longitude": -119.639,
# "grid": "DN05eu",
# "locationDesc": "US-OR",
# "attempts": 0,
# "activations": 0,
# "qsos": 0
# }
echo reference,name,latitude,longitude,grid,locationDesc,attempts,activations,qsos > $csvfile
curl -s $urlfile > $tempjsonfile
cat $tempjsonfile | jq -r '. | map( [ .reference, .name, .latitude, .longitude, .grid, .locationDesc, .attempts, .activations, .qsos ] | join("|"))' | sed 's/,$//' | sed 's/,/ /g' | tr '|' ',' | tr -d '"' | sed '1d' | sed '$d' | sed 's/^ //' >> $csvfile
rm $tempjsonfile
cat $csvfile
rm $csvfile