-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpcc
32 lines (27 loc) · 985 Bytes
/
pcc
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
#!/usr/bin/env bash
# pcc - POTA country code finder
#
# pcc without the -n switch will search for a country code
# pcc with the -n switch will search by country name
#
# all inputs are case insensitive for either search
#
# the output will be 3 lines: country prefix, country name, number of parks in the pota database
#
# NOTE: this uses the jq utility.
if [ -z "$1" ]; then
echo 'usage: pcc [ country-code | -n country-name ]'
exit 0
fi
if [ ! $(which jq) ]; then
echo "you need jq: do sudo apt install jq"
exit 1
fi
if [ "$1" = "-n" ]; then
shift # shift out the -n switch
curl -s https://api.pota.app/programs/locations | jq ".[] | select (.name | test(\"${1}\"; \"i\")) | .prefix, .name, .parks" | tr -d '"'
else
pfx="${1:0:2}" # just get first 2 characters
pfx=$(echo $pfx | tr 'a-z' 'A-Z') # and make it upcase
curl -s https://api.pota.app/programs/locations | jq ".[] | select (.prefix == \"${pfx}\") | .prefix, .name, .parks" | tr -d '"'
fi