scripts for replacing the logo according to the space status
This commit is contained in:
parent
cde60e8d35
commit
79d8daf77c
|
@ -16,6 +16,8 @@ BRANCH=${BRANCH="main"}
|
||||||
HUGO_CMD=${HUGO_CMD="hugo"}
|
HUGO_CMD=${HUGO_CMD="hugo"}
|
||||||
WWWDIR=${WWWDIR="/var/www/www"}
|
WWWDIR=${WWWDIR="/var/www/www"}
|
||||||
|
|
||||||
|
SPACEAPI_SCRIPT=${SPACEAPI_SCRIPT="python3" "$CLONE_DIR""/spaceapi.py" "$CLONE_DIR"}
|
||||||
|
|
||||||
# bugs ahead
|
# bugs ahead
|
||||||
|
|
||||||
# delete repo if it is already there
|
# delete repo if it is already there
|
||||||
|
@ -90,6 +92,9 @@ latest_remote_sha () {
|
||||||
|
|
||||||
# do the build
|
# do the build
|
||||||
build_page() {
|
build_page() {
|
||||||
|
# sync logo with spaceapi
|
||||||
|
"$SPACEAPI_SCRIPT"
|
||||||
|
|
||||||
TMPDIR=$(mktemp -d -t hugo_build_XXXXX)
|
TMPDIR=$(mktemp -d -t hugo_build_XXXXX)
|
||||||
|
|
||||||
$HUGO_CMD \
|
$HUGO_CMD \
|
||||||
|
|
|
@ -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)
|
Reference in New Issue