Add upload script from sfou in Matrix
parent
afecac487f
commit
020673af90
|
@ -0,0 +1,34 @@
|
|||
"""Script to upload an observation to SatNOGS DB Optical Observations endpoint."""
|
||||
|
||||
import json
|
||||
import requests
|
||||
|
||||
URL_API_BASE = "http://localhost:8000/api"
|
||||
TIMEOUT = 3
|
||||
TOKEN = ""
|
||||
JSON_FILEPATH = "data_to_upload/2023-01-19T17-48-40.145_data.json"
|
||||
PLOT_FILEPATH = "data_to_upload/2023-01-19T17-48-40.145_0.png"
|
||||
|
||||
|
||||
def print_json(jsn):
|
||||
"""Prints formatted json."""
|
||||
print(json.dumps(json.loads(jsn), sort_keys=True, indent=4))
|
||||
|
||||
|
||||
headers = {"Authorization": f"Token {TOKEN}"}
|
||||
|
||||
|
||||
files = {
|
||||
"data": open(JSON_FILEPATH, "rb"),
|
||||
"diagnostic_plot": open(PLOT_FILEPATH, "rb"),
|
||||
}
|
||||
resp = requests.post(
|
||||
f"{URL_API_BASE}/optical-observations/",
|
||||
timeout=TIMEOUT,
|
||||
headers=headers,
|
||||
files=files,
|
||||
)
|
||||
|
||||
|
||||
print_json(resp.text)
|
||||
print(resp.status_code)
|
Loading…
Reference in New Issue