66 lines
1.8 KiB
Python
Executable File
66 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
"""
|
|
satnogs-optical-upload
|
|
|
|
Script to upload an observation to SatNOGS DB Optical Observations endpoint.
|
|
|
|
Copyright (C) 2023, George Sfoungaris
|
|
Copyright (C) 2023, Jeff Moe
|
|
|
|
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
|
|
import argparse
|
|
|
|
TIMEOUT = 3
|
|
|
|
# Parse command line options
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("-j", "--json", help="JSON file from stvid", type=str, required=True)
|
|
parser.add_argument("-p", "--plot", help="PNG plot from stvid", type=str, required=True)
|
|
parser.add_argument("-t", "--token", help="DB API token", type=str, required=True)
|
|
parser.add_argument("-u", "--url", help="DB base URL", type=str, required=True)
|
|
args = parser.parse_args()
|
|
JSON_FILEPATH = args.json
|
|
PLOT_FILEPATH = args.plot
|
|
TOKEN = args.token
|
|
URL_API_BASE = args.url
|
|
|
|
|
|
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)
|