This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BASE_URL="${1:-https://wegwichtel.de/api}"
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)"
|
||||
GPX_FILE="$ROOT_DIR/examples/presentation-route.gpx"
|
||||
JSON_FILE="$ROOT_DIR/examples/presentation-route.json"
|
||||
|
||||
for command in curl python3; do
|
||||
command -v "$command" >/dev/null 2>&1 || {
|
||||
echo "Fehler: $command wird benötigt." >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
|
||||
read_json() {
|
||||
python3 - "$JSON_FILE" "$1" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
with open(sys.argv[1], encoding='utf-8') as handle:
|
||||
data = json.load(handle)
|
||||
value = data
|
||||
for part in sys.argv[2].split('.'):
|
||||
value = value[int(part)] if part.isdigit() else value[part]
|
||||
print(value)
|
||||
PY
|
||||
}
|
||||
|
||||
NAME="$(read_json name)"
|
||||
DESCRIPTION="$(read_json description)"
|
||||
|
||||
echo "Lege Beispielstrecke über $BASE_URL an …"
|
||||
ROUTE_RESPONSE="$(curl --fail --silent --show-error \
|
||||
-X POST "$BASE_URL/routes" \
|
||||
-F "name=$NAME" \
|
||||
-F "description=$DESCRIPTION" \
|
||||
-F "gpx=@$GPX_FILE;type=application/gpx+xml")"
|
||||
|
||||
ROUTE_ID="$(python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])' <<<"$ROUTE_RESPONSE")"
|
||||
|
||||
rollback() {
|
||||
echo "Upload fehlgeschlagen. Entferne die unvollständige Beispielstrecke $ROUTE_ID …" >&2
|
||||
curl --fail --silent --show-error -X DELETE "$BASE_URL/routes/$ROUTE_ID" >/dev/null || true
|
||||
}
|
||||
trap rollback ERR
|
||||
|
||||
POI_COUNT="$(python3 -c 'import json,sys; print(len(json.load(open(sys.argv[1], encoding="utf-8"))["pois"]))' "$JSON_FILE")"
|
||||
for ((index=0; index<POI_COUNT; index+=1)); do
|
||||
TITLE="$(read_json "pois.$index.title")"
|
||||
POI_DESCRIPTION="$(read_json "pois.$index.description")"
|
||||
LAT="$(read_json "pois.$index.lat")"
|
||||
LON="$(read_json "pois.$index.lon")"
|
||||
RADIUS="$(read_json "pois.$index.triggerRadiusM")"
|
||||
SEQUENCE="$(read_json "pois.$index.sequence")"
|
||||
|
||||
curl --fail --silent --show-error \
|
||||
-X POST "$BASE_URL/routes/$ROUTE_ID/pois" \
|
||||
-F "title=$TITLE" \
|
||||
-F "description=$POI_DESCRIPTION" \
|
||||
-F "lat=$LAT" \
|
||||
-F "lon=$LON" \
|
||||
-F "triggerRadiusM=$RADIUS" \
|
||||
-F "sequence=$SEQUENCE" >/dev/null
|
||||
echo " Trackpunkt $((index + 1))/$POI_COUNT: $TITLE"
|
||||
done
|
||||
|
||||
trap - ERR
|
||||
cat <<EOF
|
||||
Beispielstrecke erfolgreich angelegt.
|
||||
Server-ID: $ROUTE_ID
|
||||
API: $BASE_URL/routes/$ROUTE_ID
|
||||
|
||||
Hinweis: POST /routes setzt activated_at nicht. Die Strecke bleibt daher zunächst unveröffentlicht und ist für die serverseitige Prüfung vorgesehen.
|
||||
EOF
|
||||
Reference in New Issue
Block a user