app: handle weird json responses
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Victoria Fierce 2023-03-21 07:22:58 +01:00
parent af0eb90e42
commit c04c09d127

10
app.py
View File

@ -11,10 +11,18 @@ socketio.init_app(app, cors_allowed_origins="*")
CURRENT_LISTENERS = 0
def parse_stats(stats):
if isinstance(stats, list):
for stream in stats:
if stream['listenurl'] == 'http://hackerbots.net:8000/radio.mp3':
return stream
else:
return stats
def heartbeat():
global CURRENT_LISTENERS
backendFetch = requests.get('http://hackerbots.net:8000/status-json.xsl')
stats = backendFetch.json()['icestats']['source']
stats = parse_stats(backendFetch.json()['icestats']['source'])
print(stats)
return {
'title': stats.get('title', 'Unknown Track'),