diff --git a/chch-status.sh b/chch-status.sh index a588780..9e02729 100755 --- a/chch-status.sh +++ b/chch-status.sh @@ -16,6 +16,8 @@ STATUS_NULL_DELAY_MINUTES=10 STATUS_NULL_TIMEOUT_MINUTES=180 STATUS_MSG_CLOSED="Geschlossen | Closed" STATUS_MSG_OPEN="Geöffnet | Open" +YAMMAT_JSON_URL="http://localhost:9991/backup/inventory.json" +BEVERAGE_SUPPLY_TMP="/tmp/chch-beverage-supply-tmp" WIKI_PATH="/var/www/chch/" WIKI_IMAGE_CLOSED="ChCh_closed.png" WIKI_IMAGE_OPEN="ChCh_open.png" @@ -85,8 +87,15 @@ case $STATUS in ;; esac +BEVERAGE_SUPPLY="$(wget -O- "$YAMMAT_JSON_URL" 2>/dev/null | jq -rc "[ .[] | select( . | .amount > 0 ) | { value: .amount, unit: \"btl\", name: .name, description: ([(.price/100), \"€\"]|join(\" \")) } ]")" +if [ -z "$BEVERAGE_SUPPLY" ]; then + BEVERAGE_SUPPLY="$(cat $BEVERAGE_SUPPLY_TMP)" +else + echo "$BEVERAGE_SUPPLY" > "$BEVERAGE_SUPPLY_TMP" +fi + # The status file for spaceapi.ccc.de and for our IRC bot. -sed "s/%%STATUS%%/${API_STATUS}/;s/%%MESSAGE%%/${API_STATUS_MSG}/;s/%%LASTCHANGE%%/${TIMESTAMP_LASTCHANGE}/" "$JSON_FILE_TEMPL" > "$JSON_FILE_TMP" +sed "s/%%STATUS%%/${API_STATUS}/;s/%%MESSAGE%%/${API_STATUS_MSG}/;s/%%LASTCHANGE%%/${TIMESTAMP_LASTCHANGE}/;s/%%BEVERAGE_SUPPLY%%/${BEVERAGE_SUPPLY}/" "$JSON_FILE_TEMPL" | jq . > "$JSON_FILE_TMP" chown --reference="$JSON_FILE_TEMPL" "$JSON_FILE_TMP" chmod --reference="$JSON_FILE_TEMPL" "$JSON_FILE_TMP" mv "$JSON_FILE_TMP" "$JSON_FILE" diff --git a/include/chch.json.template b/include/chch.json.template index cecf303..6cba7e8 100644 --- a/include/chch.json.template +++ b/include/chch.json.template @@ -30,6 +30,9 @@ "closed": "http://chaoschemnitz.de/chch_closed.png" } }, + "sensors": { + "beverage_supply": %%BEVERAGE_SUPPLY%% + }, "feeds": { "calendar": { "type": "ical",