68 lines
1.9 KiB
Markdown
68 lines
1.9 KiB
Markdown
# Python-Werkzeuge für die Wegwichtel-REST-API
|
|
|
|
Die Skripte benötigen nur Python 3 und die Standardbibliothek. Node.js, `curl` und zusätzliche Python-Pakete sind auf dem aufrufenden Rechner nicht erforderlich.
|
|
|
|
## Authentifizierung
|
|
|
|
Jeder Request wird zunächst mit den bereits bekannten Zugangsdaten oder ohne Zugangsdaten ausgeführt. Antwortet ein vorgeschalteter Webserver mit `401 Unauthorized`, fragt das Werkzeug Benutzername und Passwort interaktiv ab und wiederholt denselben Request. Das Passwort wird mit `getpass` ohne Bildschirmausgabe eingelesen.
|
|
|
|
Optionale Umgebungsvariablen:
|
|
|
|
```bash
|
|
export WEGWICHTEL_URL='https://wegwichtel.de'
|
|
export WEGWICHTEL_USER='florian'
|
|
# WEGWICHTEL_PASSWORD nur für unbeaufsichtigte Aufrufe verwenden.
|
|
```
|
|
|
|
Alle Skripte unterstützen außerdem `--base-url` und `--username`. Fehlende fachliche Parameter werden interaktiv abgefragt.
|
|
|
|
## Routen
|
|
|
|
```bash
|
|
python3 tools/python/create_route.py
|
|
python3 tools/python/update_route.py
|
|
python3 tools/python/append_route.py
|
|
python3 tools/python/delete_route.py
|
|
python3 tools/python/restore_route.py
|
|
```
|
|
|
|
## POIs
|
|
|
|
```bash
|
|
python3 tools/python/create_poi.py
|
|
python3 tools/python/update_poi.py
|
|
python3 tools/python/delete_poi.py
|
|
```
|
|
|
|
Beim Löschen eines POIs entfernt die API auch dessen Bilder und Audiodatei.
|
|
|
|
## Bilder
|
|
|
|
```bash
|
|
python3 tools/python/create_picture.py
|
|
python3 tools/python/update_picture.py
|
|
python3 tools/python/delete_picture.py
|
|
```
|
|
|
|
## Audio
|
|
|
|
```bash
|
|
python3 tools/python/create_audio.py
|
|
python3 tools/python/update_audio.py
|
|
python3 tools/python/delete_audio.py
|
|
```
|
|
|
|
## Beispiel mit Parametern
|
|
|
|
```bash
|
|
python3 tools/python/create_picture.py \
|
|
--base-url https://wegwichtel.de \
|
|
--route-id 1 \
|
|
--poi-id 7 \
|
|
--file ./eiche.jpg \
|
|
--caption 'Blick auf die Baumkrone' \
|
|
--sequence 0
|
|
```
|
|
|
|
Die Multipart-Hilfsfunktion sendet für Dateien absichtlich keinen behaupteten MIME-Typ. Der Server bestimmt das Format aus dem Dateiinhalt.
|