41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Lädt ein Bild zu einem POI hoch."""
|
|
|
|
import argparse
|
|
from collections.abc import Sequence
|
|
|
|
from common import add_common_arguments, ask, ask_path, client_from_args, run
|
|
|
|
|
|
def build_parser() -> argparse.ArgumentParser:
|
|
parser = argparse.ArgumentParser(description="Bild zu einem POI hochladen")
|
|
add_common_arguments(parser)
|
|
parser.add_argument("--route-id", type=int)
|
|
parser.add_argument("--poi-id", type=int)
|
|
parser.add_argument("--file")
|
|
parser.add_argument("--caption")
|
|
parser.add_argument("--sequence", type=int)
|
|
return parser
|
|
|
|
|
|
def main(argv: Sequence[str] | None = None):
|
|
args = build_parser().parse_args(argv)
|
|
client = client_from_args(args)
|
|
route_id = ask("Route-ID", args.route_id, required=True, cast=int)
|
|
poi_id = ask("POI-ID", args.poi_id, required=True, cast=int)
|
|
picture = ask_path("Bilddatei", args.file)
|
|
fields = {
|
|
"caption": ask("Bildbeschreibung", args.caption),
|
|
"sequence": ask("Reihenfolge (leer: automatisch)", args.sequence, cast=int),
|
|
}
|
|
return client.request(
|
|
"POST",
|
|
f"/api/routes/{route_id}/pois/{poi_id}/pictures",
|
|
fields=fields,
|
|
files={"picture": picture},
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run(main)
|