-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_MPC_obs.py
48 lines (34 loc) · 1.29 KB
/
get_MPC_obs.py
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
import requests
from openpyxl import load_workbook
# == INPUTS ==
spreadsheet_name = "obs.xlsx"
num_asteroids = 22
# which row the table entries begin from on the spreadsheet
# (e.g. table_offset = 5 if first entry is at C5)
table_offset = 5
# the column on which the object names/ids are kept
# (e.g. ID_col = "C" if first entry is at C5)
ID_col = "C"
observatory_suffix = "T09" # e.g. T09 = Subaru
# == == == == ==
print("Reading objects from spreadsheet...")
workbook = load_workbook(filename=spreadsheet_name)
sheet = workbook.active
asteroid_ids = []
for i in range(num_asteroids):
asteroid_ids.append(sheet[ID_col + str(int(table_offset + i))].value + " " + observatory_suffix)
print("Retrieving observations from Minor Planet Center...")
url = "https://data.minorplanetcenter.net/api/wamo"
obs_list = asteroid_ids
result = requests.get(url, json=obs_list)
observations = result.json()
# The Flask endpoint can also provide the original WAMO string
result = requests.get(url, json={'return_type': 'string', 'obs': obs_list})
observations = result.text
observations = observations.split("\n")
print("Writing observation states into MPC_stats.txt...")
with open("MPC_stats.txt", "w") as text_file:
for o in observations:
text_file.write(o)
text_file.write("\n")
print("Done!")