Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfalkvidd/c2c75d23bb648bf539aadf5913f44ade to your computer and use it in GitHub Desktop.
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
#!/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