refactor init variables and modules

This commit is contained in:
deflax 2024-01-07 02:03:15 +02:00
parent d6906ea14f
commit 64373534d6

View file

@ -1,40 +1,40 @@
import os import os
import logging import logging
import json import json
import time
from datetime import datetime from datetime import datetime
from flask import Flask, render_template, jsonify, request from flask import Flask, render_template, jsonify, request
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from core_client import Client from core_client import Client
import time
app = Flask(__name__) app = Flask(__name__)
scheduler = BackgroundScheduler() scheduler = BackgroundScheduler()
# Log handlers # Log handlers
logger_api = logging.getLogger('waitress') logger_api = logging.getLogger('waitress')
logger_api.setLevel(os.environ.get('SCHEDULER_LOG_LEVEL', 'INFO').upper())
logger_job = logging.getLogger('apscheduler') logger_job = logging.getLogger('apscheduler')
logger_job.setLevel(os.environ.get('SCHEDULER_LOG_LEVEL', 'INFO').upper()) log_level = os.environ.get('SCHEDULER_LOG_LEVEL', 'INFO').upper()
logger_api.setLevel(log_level)
logger_job.setLevel(log_level)
# Variables # Variables
CORE_SYNC_PERIOD = 30 CORE_SYNC_PERIOD = int(os.environ.get('CORE_SYNC_PERIOD', 30))
api_hostname = os.environ.get('CORE_API_HOSTNAME') api_hostname = os.environ.get('CORE_API_HOSTNAME', 'stream.example.com')
api_port = os.environ.get('CORE_API_PORT') api_username = os.environ.get('CORE_API_AUTH_USERNAME', 'admin')
api_username = os.environ.get('CORE_API_AUTH_USERNAME') api_password = os.environ.get('CORE_API_AUTH_PASSWORD', 'pass')
api_password=os.environ.get('CORE_API_AUTH_PASSWORD')
# Init # Init
database = {} database = {}
prio = 0 prio = 0
head = {} head = {}
epg_json = open('/config/epg.json', 'r')
with open('/config/epg.json', 'r') as epg_json:
epg = json.load(epg_json) epg = json.load(epg_json)
logger_api.info(epg)
for i in epg:
logger_api.info(i)
epg_json.close() epg_json.close()
print(epg)
logger_api.info(epg)
# Helper functions # Helper functions
def find_event_entry(events, target_name): def find_event_entry(events, target_name):
for entry in events: for entry in events: