1
0
Fork 0

python requirements, bang path

main
Jeff Moe 2023-06-25 12:38:29 -06:00
parent bd0d1e2235
commit 57e02a3fa2
3 changed files with 3 additions and 53 deletions

View File

@ -0,0 +1 @@
requests

2
upload
View File

@ -1,3 +1,5 @@
#!/usr/bin/env python3
"""
upload_optical_v2.py

View File

@ -1,53 +0,0 @@
"""
upload_optical_v2.py
Script to upload an observation to SatNOGS DB Optical Observations endpoint.
Copyright (C) 2023, George Sfoungaris
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
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)