"""Resource tracker""" import os import logging from dotenv import load_dotenv from apscheduler.schedulers.background import BackgroundScheduler from rival_regions_wrapper.rival_regions_wrapper import Client load_dotenv() SCHEDULER = BackgroundScheduler( daemon=True, job_defaults={'misfire_grace_time': 300}, ) SCHEDULER.start() # logger LOGGER = logging.getLogger('resource_tracker') LOGGER.setLevel(logging.DEBUG) # scheduler logger SCHEDULER_LOGGER = logging.getLogger('apscheduler') SCHEDULER_LOGGER.setLevel(logging.DEBUG) # RR wrapper logger RR_WRAPPER_LOGGER = logging.getLogger('rival_regions_wrapper') RR_WRAPPER_LOGGER.setLevel(logging.DEBUG) # create file handler FILE_HANDLER = logging.FileHandler('output.log') FILE_HANDLER.setLevel(logging.DEBUG) # create console handler STREAM_HANDLER = logging.StreamHandler() STREAM_HANDLER.setLevel(logging.INFO) # create formatter and add it to the handlers FORMATTER = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') STREAM_HANDLER.setFormatter(FORMATTER) FILE_HANDLER.setFormatter(FORMATTER) # add the handlers to logger LOGGER.addHandler(STREAM_HANDLER) LOGGER.addHandler(FILE_HANDLER) SCHEDULER_LOGGER.addHandler(STREAM_HANDLER) SCHEDULER_LOGGER.addHandler(FILE_HANDLER) RR_WRAPPER_LOGGER.addHandler(STREAM_HANDLER) RR_WRAPPER_LOGGER.addHandler(FILE_HANDLER) RR_WRAPPER = Client(show_window=os.environ['SHOW_WINDOW'].lower() == 'true') RR_WRAPPER.set_credentials({ 'login_method': os.environ['LOGIN_METHOD'], 'username': os.environ['USERNAME'], 'password': os.environ['PASSWORD'] }) STATE_ID = os.environ['STATE_ID'] CAPITAL_ID = os.environ['CAPITAL_ID'] RESOURCE_IDS = { 0: 'gold', 3: 'oil', 4: 'ore', 11: 'uranium', 15: 'diamond', } RESOURCE_NAMES = { 'gold': 0, 'oil': 3, 'ore': 4, 'uranium': 11, 'diamond': 15, } RESOURCE_MAX = { 0: 2500, 3: 600, 4: 500, 11: 60, 15: 75, }