Trinity-SpaceData / fetch.py
STAR-future's picture
LittleBoy SpaceData v1: licence-checked public space data
5ab75a9 verified
Raw History Blame
1.89 kB
"""Download, from the original providers and under their terms, the LittleBoy-SpaceData sources that are not
redistributed. Writes <out>/<name> and <out>/SHA256SUMS.txt. Standard library only.
python fetch.py --out external
"""
import argparse
import hashlib
import sys
import time
import urllib.request
from pathlib import Path
GP = "https://celestrak.org/NORAD/elements/gp.php?GROUP={g}&FORMAT=tle"
URLS = {f"celestrak/{g}.tle": GP.format(g=g) for g in
("active", "analyst", "cosmos-1408-debris", "cosmos-2251-debris", "fengyun-1c-debris", "iridium-33-debris",
"starlink", "oneweb")}
URLS["launch_library/upcoming.json"] = "https://ll.thespacedevs.com/2.3.0/launches/upcoming/?limit=100&format=json"
URLS["gaia/dr3_sample_1000.csv"] = ("https://gea.esac.esa.int/tap-server/tap/sync?REQUEST=doQuery&LANG=ADQL&FORMAT=csv&QUERY="
"SELECT+TOP+1000+source_id,ra,dec,parallax,pmra,pmdec,phot_g_mean_mag+FROM+gaiadr3.gaia_source")
def main(argv):
ap = argparse.ArgumentParser()
ap.add_argument("--out", required=True)
a = ap.parse_args(argv)
out = Path(a.out)
sums = []
for name, url in URLS.items():
d = out / name
d.parent.mkdir(parents=True, exist_ok=True)
req = urllib.request.Request(url, headers={"User-Agent": "LittleBoy-SpaceData-fetch/1.0"})
with urllib.request.urlopen(req, timeout=120) as r: # noqa: S310 - fixed provider URLs
d.write_bytes(r.read())
sums.append(f"{hashlib.sha256(d.read_bytes()).hexdigest()} {name}")
print(name, d.stat().st_size, flush=True)
time.sleep(2) # one request at a time, as the providers ask
(out / "SHA256SUMS.txt").write_text("\n".join(sums) + "\n", encoding="utf-8")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))