fix the mess created by chatgpt

This commit is contained in:
deflax 2024-01-07 03:14:15 +02:00
parent 2b0ba2181b
commit e4bd771275

View file

@ -69,9 +69,10 @@ def process_running_channel(database, scheduler, stream_id, stream_name, stream_
# Helper function to remove channel from the database # Helper function to remove channel from the database
def remove_channel_from_database(database, scheduler, stream_id, stream_name, state): def remove_channel_from_database(database, scheduler, stream_id, stream_name, state):
logger_job.info(f'{stream_id} ({stream_name}) has been removed from the database. Reason: {state.exec}') if stream_id in database:
database.pop(stream_id) logger_job.info(f'{stream_id} ({stream_name}) has been removed from the database. Reason: {state.exec}')
scheduler.remove_job(stream_id) database.pop(stream_id)
scheduler.remove_job(stream_id)
# Helper function to find match a stream name with epg.json # Helper function to find match a stream name with epg.json
def find_event_entry(events, target_name): def find_event_entry(events, target_name):
@ -122,6 +123,7 @@ def core_api_sync():
process_running_channel(database, scheduler, stream_id, stream_name, stream_description, stream_hls_url) process_running_channel(database, scheduler, stream_id, stream_name, stream_description, stream_hls_url)
else: else:
remove_channel_from_database(database, scheduler, stream_id, stream_name, state) remove_channel_from_database(database, scheduler, stream_id, stream_name, state)
new_ids.remove(stream_id)
# Cleanup orphaned references # Cleanup orphaned references
orphan_keys = [key for key in database if key not in new_ids] orphan_keys = [key for key in database if key not in new_ids]
@ -139,11 +141,11 @@ def show_scheduled_tasks():
# Login # Login
try: try:
client = Client(base_url='https://' + api_hostname, username=api_username, password=api_password) client = Client(base_url='https://' + api_hostname, username=api_username, password=api_password)
logger_job.info('Logging in to Datarhei Core API ' + api_username + '@' + api_hostname) logger_api.info('Logging in to Datarhei Core API ' + api_username + '@' + api_hostname)
client.login() client.login()
except Exception as err: except Exception as err:
logger_job.error('client login error') logger_api.error('client login error')
logger_job.error(err) logger_api.error(err)
# Schedule datarhei core api sync # Schedule datarhei core api sync
scheduler.add_job(func=core_api_sync, trigger="interval", seconds=CORE_SYNC_PERIOD, id="core_api_sync") scheduler.add_job(func=core_api_sync, trigger="interval", seconds=CORE_SYNC_PERIOD, id="core_api_sync")