1
0
Fork 0

Add upload script from sfou in Matrix

main
Jeff Moe 2023-06-25 10:25:17 -06:00
parent afecac487f
commit 020673af90
1 changed files with 34 additions and 0 deletions

View File

@ -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)