lolwtf this shit actually works

This commit is contained in:
Hausmeister (ax41-1.fsn.mon2.de) 2024-01-18 22:22:02 +01:00
commit 14dc277816
4 changed files with 74 additions and 0 deletions

24
docker-compose.yaml Normal file
View File

@ -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

6
src/Dockerfile Normal file
View File

@ -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"]

43
src/app.py Normal file
View File

@ -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)

1
src/requirements.txt Normal file
View File

@ -0,0 +1 @@
Flask>=3.0.1