25 lines
1.0 KiB
Python
25 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
from common import add_common_arguments, ask, ask_path, ask_with_default, client_from_args, run
|
|
|
|
parser = argparse.ArgumentParser(description="Wegwichtel-Route ändern")
|
|
add_common_arguments(parser)
|
|
parser.add_argument("--route-id", type=int)
|
|
parser.add_argument("--gpx")
|
|
args = parser.parse_args()
|
|
|
|
def action():
|
|
client = client_from_args(args)
|
|
route_id = ask("Route-ID", args.route_id, required=True, cast=int)
|
|
current = client.request("GET", f"/api/routes/{route_id}")
|
|
fields = {
|
|
"name": ask_with_default("Name", current.get("name", "")),
|
|
"description": ask_with_default("Beschreibung", current.get("description", "")),
|
|
"schoolName": ask_with_default("Schule", current.get("schoolName", "")),
|
|
}
|
|
gpx = ask_path("Neue GPX-Datei (leer: unverändert)", args.gpx, required=False)
|
|
if gpx:
|
|
return client.request("PUT", f"/api/routes/{route_id}", fields=fields, files={"gpx": gpx})
|
|
return client.request("PUT", f"/api/routes/{route_id}", json_body=fields)
|
|
run(action)
|