-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_project_pluto_test_data.py
More file actions
70 lines (55 loc) · 1.91 KB
/
Copy pathfetch_project_pluto_test_data.py
File metadata and controls
70 lines (55 loc) · 1.91 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Download small Project Pluto HTML fixtures for parser regression tests.
Run from the repository root:
python fetch_project_pluto_test_data.py
If a NEOCP designation is no longer available, replace A11D0Xd below with a
current NEOCP candidate from the left panel of the app.
"""
from pathlib import Path
import requests
PROJECT_PLUTO_URL = "https://www.projectpluto.com/cgi-bin/fo/fo_serve.cgi"
# Keep one known object and one NEOCP-style object.
# If A11D0Xd disappears from NEOCP, replace it with a current candidate.
OBJECTS = {
"project_pluto_A11D0Xd.html": "A11D0Xd",
"project_pluto_99942.html": "99942",
}
BASE_PARAMS = {
"year": "now",
"n_steps": 10,
"stepsize": "1h",
"mpc_code": "X93",
"faint_limit": 99,
"ephem_type": 0,
"sigmas": "on",
"element_center": -2,
"epoch": "default",
"resids": 0,
"language": "e",
"file_no": 0,
}
HEADERS = {
"User-Agent": "NEOCP Explorer parser fixture downloader (https://github.com/Anduin-source/NEOCP_Explorer)"
}
def download_fixture(filename: str, object_name: str) -> None:
params = dict(BASE_PARAMS)
params["obj_name"] = object_name
print(f"Downloading {object_name} ...")
response = requests.get(PROJECT_PLUTO_URL, params=params, headers=HEADERS, timeout=30)
response.raise_for_status()
text = response.text
if "Ephemerides for" not in text:
raise RuntimeError(
f"Project Pluto did not return an ephemeris table for {object_name}.\n"
"If this is the NEOCP object, replace it with a current candidate."
)
out_dir = Path("test_data")
out_dir.mkdir(exist_ok=True)
out_path = out_dir / filename
out_path.write_text(text, encoding="utf-8")
print(f"Saved {out_path}")
def main() -> None:
for filename, object_name in OBJECTS.items():
download_fixture(filename, object_name)
print("Done.")
if __name__ == "__main__":
main()