Last active
May 30, 2020 12:46
-
-
Save cbassa/123967406076d4711be40094e0bce4fb to your computer and use it in GitHub Desktop.
Upload missing waterfalls
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
#!/usr/bin/env python3 | |
import os | |
import glob | |
import requests | |
import shutil | |
import argparse | |
from datetime import datetime | |
if __name__ == "__main__": | |
# Parse input arguments | |
parser = argparse.ArgumentParser(description="Upload missing waterfall files") | |
parser.add_argument("-s", "--station", help="Ground station ID", type=int, default=39) | |
parser.add_argument("-t", "--starttime", help="Copy observations after this time (YYYY-MM-DDTHH:MM:SS)", default="2020-05-25T00:00:00") | |
parser.add_argument("-p", "--path", help="SatNOGS data path (e.g. /tmp/.satnogs/data)", default="/home/bassa/satnogs/vhf_data") | |
args = parser.parse_args() | |
# Check arguments | |
if args.station is not None: | |
ground_station = args.station | |
if args.starttime is not None: | |
tend = datetime.strptime(args.starttime, "%Y-%m-%dT%H:%M:%S") | |
if args.path is not None: | |
satnogs_dir = args.path | |
# Open connection | |
client = requests.session() | |
next_url = f"https://network.satnogs.org/api/observations/?ground_station={ground_station:d}" | |
# Load pages | |
while next_url: | |
r = client.get(next_url) | |
if 'next' in r.links: | |
next_url = r.links['next']['url'] | |
else: | |
logging.debug("No further pages with observations") | |
next_url = None | |
if not r.json(): | |
logging.info("Ground station has no observations yet") | |
break | |
# r.json() is a list of dicts/observations | |
for o in r.json(): | |
# Get start time | |
tstart = datetime.strptime(o["start"].replace("Z", ""), "%Y-%m-%dT%H:%M:%S") | |
# Check if observation has audio | |
if o["archive_url"] is not None: | |
has_audio = True | |
else: | |
has_audio = False | |
# Check if observation has waterfall | |
if o["waterfall"] is not None: | |
has_waterfall = True | |
else: | |
has_waterfall = False | |
# Missing waterfall | |
if has_audio is True and has_waterfall is False: | |
# Copy waterfall file | |
fnames = glob.glob(os.path.join(satnogs_dir, f"complete/waterfall_{o['id']:d}_*.png")) | |
for fname in fnames: | |
if os.path.exists(fname): | |
shutil.copy(fname, satnogs_dir) | |
print(f"Copying {fname} to {satnogs_dir}") | |
else: | |
print(f"{fname} not found") | |
# Exit | |
if tstart < tend: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment