Merge pull request 'SpaceAPI on our homepage' (#86) from moke/Homepage:spaceapi into main

Reviewed-on: #86
pull/87/head
alex 2023-06-28 22:27:03 +02:00
commit 69f8f48fcc
9 changed files with 297 additions and 0 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 34 KiB

BIN
assets/logo_closed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

79
assets/logo_closed.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/logo_open.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

78
assets/logo_open.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/logo_unknown.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

79
assets/logo_unknown.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -90,6 +90,9 @@ latest_remote_sha () {
# do the build
build_page() {
# sync logo with spaceapi
"python3" "$CLONE_DIR""/spaceapi.py" "$CLONE_DIR"
TMPDIR=$(mktemp -d -t hugo_build_XXXXX)
$HUGO_CMD \

58
spaceapi.py Executable file
View File

@ -0,0 +1,58 @@
# 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 + "/assets/logo_open"
space_closed: str = path + "/assets/logo_closed"
space_unknown: str = path + "/assets/logo_unknown"
space_logo: str = path + "/assets/logo"
extensions: list[str] = [".png", ".svg"]
# every extension needs to be linked
def link(src: str, dest: str):
for ext in extensions:
try:
os.symlink(src + ext, dest + ext)
print("linked " + dest + ext + " to " + src + ext)
except:
print("cannot link " + dest + ext + " to " + src + ext)
def delete(file: str):
for ext in extensions:
try:
os.remove(file + ext)
print("deleted " + file + ext)
except:
try:
os.unlink(file + ext)
print("unlinked "+ file + ext)
except:
print(file + ext + " is already deleted and unlinked")
if __name__ == "__main__":
delete(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
# the linking seems to be the wrong way around, but it links correct
# the link is pointing from dest to src (https://docs.python.org/3/library/os.html)
link(path, space_logo)
except:
link(space_unknown, space_logo)