diff options
Diffstat (limited to 'official-site/add-event.sh')
| -rwxr-xr-x | official-site/add-event.sh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/official-site/add-event.sh b/official-site/add-event.sh new file mode 100755 index 0000000..52c2d95 --- /dev/null +++ b/official-site/add-event.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# Usage: bash add-event.sh <json-file> +# The JSON file should match the Event schema (see CLAUDE.md). +# id, createdAt, updatedAt, _version, _deleted, _lastChangedAt are auto-managed. +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" +[ -f "$REPO_ROOT/.env" ] && set -a && source "$REPO_ROOT/.env" && set +a + +ENDPOINT="https://APP_SYNC_ENDPOINT_REDACTED/graphql" +API_KEY="${APP_SYNC_API_KEY:-APP_SYNC_API_KEY_REDACTED}" + +JSON_FILE="${1:-}" +if [ -z "$JSON_FILE" ]; then + echo "Usage: $0 <event-json-file>" + exit 1 +fi + +INPUT=$(python3 -c " +import json, sys +with open('$JSON_FILE') as f: + data = json.load(f) +# Remove read-only / auto-managed fields +for k in ['id', 'createdAt', 'updatedAt', '_version', '_deleted', '_lastChangedAt', '_note']: + data.pop(k, None) +# Remove null fields (optional) +data = {k: v for k, v in data.items() if v is not None} +print(json.dumps(data)) +") + +QUERY='mutation CreateEvent($input: CreateEventInput!) { createEvent(input: $input) { id type date title venueName published } }' +PAYLOAD=$(python3 -c " +import json, sys +q = '$QUERY' +inp = $INPUT +print(json.dumps({'query': q, 'variables': {'input': inp}})) +") + +echo "Creating event from $JSON_FILE ..." +RESULT=$(curl -s -X POST "$ENDPOINT" \ + -H "Content-Type: application/json" \ + -H "x-api-key: $API_KEY" \ + -d "$PAYLOAD") + +echo "$RESULT" | python3 -m json.tool +echo "" +echo "Done. Run 'bash deploy.sh' to rebuild the site." |
