Fix radio generator too many requests; logging some parts

This commit is contained in:
localhost_frssoft 2022-11-07 01:21:49 +03:00
parent ae1cba2e98
commit 74f9a732ef
3 changed files with 11 additions and 3 deletions

View file

@ -1,6 +1,6 @@
from src.fw_api import select_instance
from src.fw_radios import list_radios
import json
import json, sys
from loguru import logger
from pyfzf.pyfzf import FzfPrompt
@ -8,6 +8,8 @@ fzf = FzfPrompt()
def main():
logger.remove()
logger.add(sys.stderr, filter='src.fw_api')
logger.add(sys.stderr, filter='src.fw_radios')
while True:
menu = ('Radios', 'Switch instance' )
ids = fzf.prompt(menu)

View file

@ -64,6 +64,10 @@ def post_radio_session(requested_radio):
def get_track_radio(radio_session):
r = s.post(f'https://{instance}/api/v1/radios/tracks/',json=radio_session)
return r.json()
try:
r.raise_for_status()
return r.json()
except:
logger.exception('Radio: get next track failed')

View file

@ -49,6 +49,7 @@ def radio_generator(radio_session_id):
break
count_t += 1
if count_t >= 60:
count_t = 0
radio_get_track(radio_session_id)
logger.info('Radio generator stopped')
@ -100,7 +101,8 @@ def radio_load(id_radio=None, type_radio='custom'):
def radio_get_track(radio_session_id):
radio_context = get_track_radio({'session': radio_session_id})
if not radio_context:
return
if radio_context == "Radio doesn't have more candidates":
return
else: