app: handle weird json responses
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
af0eb90e42
commit
c04c09d127
10
app.py
10
app.py
@ -11,10 +11,18 @@ socketio.init_app(app, cors_allowed_origins="*")
|
|||||||
|
|
||||||
CURRENT_LISTENERS = 0
|
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():
|
def heartbeat():
|
||||||
global CURRENT_LISTENERS
|
global CURRENT_LISTENERS
|
||||||
backendFetch = requests.get('http://hackerbots.net:8000/status-json.xsl')
|
backendFetch = requests.get('http://hackerbots.net:8000/status-json.xsl')
|
||||||
stats = backendFetch.json()['icestats']['source']
|
stats = parse_stats(backendFetch.json()['icestats']['source'])
|
||||||
print(stats)
|
print(stats)
|
||||||
return {
|
return {
|
||||||
'title': stats.get('title', 'Unknown Track'),
|
'title': stats.get('title', 'Unknown Track'),
|
||||||
|
Loading…
Reference in New Issue
Block a user