spaceapi/src/app.py

44 lines
1.0 KiB
Python
Raw Normal View History

2024-01-18 22:22:02 +01:00
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)