From 14dc277816b2402b77922ba299dc18bfb6cabbc1 Mon Sep 17 00:00:00 2001 From: "Hausmeister (ax41-1.fsn.mon2.de)" Date: Thu, 18 Jan 2024 22:22:02 +0100 Subject: [PATCH] lolwtf this shit actually works --- docker-compose.yaml | 24 ++++++++++++++++++++++++ src/Dockerfile | 6 ++++++ src/app.py | 43 +++++++++++++++++++++++++++++++++++++++++++ src/requirements.txt | 1 + 4 files changed, 74 insertions(+) create mode 100644 docker-compose.yaml create mode 100644 src/Dockerfile create mode 100644 src/app.py create mode 100644 src/requirements.txt diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..7708f3c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + spaceapi: + image: spaceapi + build: + context: src + networks: + - ingress + - default + deploy: + labels: + - "shepherd.auto-update=true" + - "traefik.enable=true" + - "traefik.http.services.spaceapi.loadbalancer.server.port=5000" + - "traefik.http.routers.spaceapi.rule=Host(`api.montage2.de`)||Host(`api.chaoswest.tv`)" + - "traefik.http.routers.spaceapi.tls=true" + - "traefik.http.routers.spaceapi.tls.certresolver=default" + +networks: + ingress: + external: true + name: traefik + diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 0000000..bd244b1 --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1,6 @@ +FROM python:alpine +RUN mkdir /app +WORKDIR /app +COPY . /app +RUN pip install -r requirements.txt +ENTRYPOINT ["flask", "--app", "app", "run", "--host=0.0.0.0"] diff --git a/src/app.py b/src/app.py new file mode 100644 index 0000000..781dc0f --- /dev/null +++ b/src/app.py @@ -0,0 +1,43 @@ +import json +import urllib.request + +from flask import Flask, jsonify + +app = Flask(__name__) + +def get_jitsi_status(): + try: + content = urllib.request.urlopen("https://talk.chaoswest.tv/room-census").read() + census = json.loads(content) + return any(room["room_name"] == "cws-lounge@muc.meet.jitsi" for room in census["room_census"]) + except Exception as e: + print("shit got fucked up:") + print(e) + return None + +@app.route("/spaceapi") +def spaceapi(): + result = { + 'api': '0.13', + 'api_compatibility': ['14'], + 'space': 'chaoswest.tv', + 'logo': 'https://chaoswest.tv/logo.png', + 'url': 'https://chaoswest.tv', + 'location': { + 'lat': 50.47718, + 'lon': 12.33427, + 'address': 'FSN1-DC14', + }, + 'contact': { + 'mastodon': '@chaoswesttv@chaos.social', + } + } + + status = get_jitsi_status() + + if status: + result["state"] = { + 'open': status + } + + return jsonify(result) diff --git a/src/requirements.txt b/src/requirements.txt new file mode 100644 index 0000000..5084a60 --- /dev/null +++ b/src/requirements.txt @@ -0,0 +1 @@ +Flask>=3.0.1