-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsitetotals
36 lines (30 loc) · 1.13 KB
/
sitetotals
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
#!/bin/bash
# Enter the PiAware site stats URL below using the full site URL format, eg
# https://uk.flightaware.com/adsb/stats/user/username#stats-nnnnnn
siteurl=
# Extract the site number from the end of the URL
setSiteID() {
siteid=$(echo $siteurl | sed -e 's/^.*#stats-//')
}
# Download the URL, locate the stats JSON data, strip the HTML before and after it
getJSONdata() {
jsondata=$(curl -s $siteurl)
jsondata=$(echo $jsondata | grep "var data")
jsondata=$(echo $jsondata | sed -e 's/^.*var\sdata\s=\s//')
jsondata=$(echo $jsondata | sed -e 's/;.*$//')
}
# Extract the Aircraft Reported totals and delimit with spaces
filterAircraftReported() {
acrep=$(echo $jsondata | jq --arg jqsiteid $siteid '.sites[$jqsiteid].daily_stats[].idents' | tr "\n" " ")
}
# Extract the Positions Reported totals and delimit with spaces
filterPositionsReported() {
posrep=$(echo $jsondata | jq --arg jqsiteid $siteid '.sites[$jqsiteid].daily_stats[].positions' | tr "\n" " ")
}
setSiteID
echo "Getting totals for Site $siteid"
getJSONdata
filterAircraftReported
filterPositionsReported
echo "Aircraft reported: $acrep"
echo "Positions reported: $posrep"