Created
June 23, 2021 12:37
-
-
Save mfalkvidd/c2c75d23bb648bf539aadf5913f44ade to your computer and use it in GitHub Desktop.
Uses the Satnogs Network API to fetch all observations and output a csv file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
re='^[0-9]+$' | |
if ! [[ "$1" =~ $re ]] ; then | |
echo "Usage: $0 <station_number>" | |
exit | |
fi | |
PAGE=1 | |
OUTPUT="" | |
STATION=$1 | |
JSONFILE="observations_$STATION.json" | |
CSVFILE="observations_$STATION.csv" | |
echo "[" >> "$JSONFILE" | |
while true | |
do | |
OUTPUT=$(curl "https://network.satnogs.org/api/observations/?format=json&ground_station=$STATION&page=$PAGE") | |
if echo "$OUTPUT" | grep -q 'Invalid page'; then | |
break; | |
fi | |
if [[ $PAGE -gt 1 ]]; then | |
echo "," >> "$JSONFILE" | |
fi | |
echo "$OUTPUT" >> "$JSONFILE" | |
PAGE=$((PAGE+1)) | |
done | |
echo "]" >> "$JSONFILE" | |
echo "obs_ID,status,transmitter,satellite" > "$CSVFILE" | |
jq -r '.[][] | "\(.id),\(.status),\(.transmitter_uuid),\(.tle0)"' "$JSONFILE" >> "$CSVFILE" | |
echo "Output is in $CSVFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment