scripts for replacing the logo according to the space status

pull/86/head
Moritz Kempe 2023-06-24 23:12:04 +02:00
parent cde60e8d35
commit 79d8daf77c
2 changed files with 45 additions and 0 deletions

View File

@ -16,6 +16,8 @@ BRANCH=${BRANCH="main"}
HUGO_CMD=${HUGO_CMD="hugo"}
WWWDIR=${WWWDIR="/var/www/www"}
SPACEAPI_SCRIPT=${SPACEAPI_SCRIPT="python3" "$CLONE_DIR""/spaceapi.py" "$CLONE_DIR"}
# bugs ahead
# delete repo if it is already there
@ -90,6 +92,9 @@ latest_remote_sha () {
# do the build
build_page() {
# sync logo with spaceapi
"$SPACEAPI_SCRIPT"
TMPDIR=$(mktemp -d -t hugo_build_XXXXX)
$HUGO_CMD \

40
spaceapi.py Normal file
View File

@ -0,0 +1,40 @@
# Python Requirements
# python3
# requests
# shutil
import requests
import os
import sys
path: str = sys.argv[1]
api: str = "https://api.dezentrale.cloud/spaceapi/v14"
space_open: str = path + "/logo_open"
space_closed: str = path + "/logo_closed"
space_unknown: str = path + "/logo_unknown"
space_logo: str = path + "/logo"
extensions: list[str] = [".png", ".svg"]
# every extension needs to be linked
def link(src: str, dest: str):
for ext in extensions:
os.symlink(src + ext, dest + ext)
if __name__ == "__main__":
os.remove(space_logo)
try:
resp: requests.Response = requests.get(api)
resp_dict: dict = resp.json()
door_open: bool = resp_dict.get("state").get("open")
print(door_open)
path = ""
if door_open:
path = space_open
else:
path = space_closed
os.symlink(space_logo, path)
except:
os.symlink(space_logo, space_unknown)