from market import Market from player import Player import schedule import time from datetime import datetime from logger import logger from config import Config # Set Config Parameters MARKET_POLL_INTERVAL = Config["gather"].get("MarketPollInterval",15) PLAYER_POLL_INTERVAL = Config["gather"].get("PlayerPollInterval",15) CollectPlayerData = Config["gather"].get("CollectPlayer",False) Login = Config["gather"].get("Login",False) # Handle command arguments import argparse parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,description="",epilog="") parser.add_argument( "-p", "--player", metavar="yes/no", choices=['yes','no'], help="Collect player data?" ) parser.add_argument( "-l", "--login", metavar="yes/no", choices=['yes','no'], help="Login to Browser?" ) args = parser.parse_args() if args.player is not None: if args.player == 'yes': CollectPlayerData = True else: CollectPlayerData = False login_yesno = args.login if args.login is not None: if args.login == 'yes': Login = True else: Login = False m=Market(login=Login) p=Player() merr=0 perr=0 def jobM(): global m,merr logger.info("Gathering Market Data.") try: m.fetchData() m.commit() logger.info("Complete.") except Exception as e: logger.error(f"{e}") merr +=1 if merr >= 3: merr=0 m=Market() def jobP(): global p,perr logger.info("Gathering Player Data.") try: p.fetchData() p.commit() logger.info("Complete.") except Exception as e: logger.error(f"{e}") perr +=1 if perr >= 3: perr=0 p=Player() schedule.every(MARKET_POLL_INTERVAL).minutes.do(jobM) jobM() if CollectPlayerData == 'yes': schedule.every(PLAYER_POLL_INTERVAL).minutes.do(jobP) jobP() while 1: schedule.run_pending() time.sleep(1)