123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- from market import Market
- from player import Player
- import marketMonitor
- import schedule
- import time
- from datetime import datetime
- from logger import logger
- import argparse
- import sys
- def parse_args():
- parser = argparse.ArgumentParser(
- formatter_class=argparse.RawDescriptionHelpFormatter,
- description="Gather Market Data Script",
- epilog="",
- )
- parser.add_argument(
- "-p",
- "--player",
- action='store_true',
- help="Collect player data?"
- )
- parser.add_argument(
- "-l",
- "--login",
- action='store_true',
- help="Login to Browser?"
- )
- return parser.parse_args()
- def create_market(login):
- return Market(login=login)
- def create_player():
- return Player()
- def main():
- try:
- args = parse_args()
- except argparse.ArgumentError as e:
- logger.error(f"Argument parsing error: {e}")
- sys.exit(1)
- m = create_market(login=args.login)
- p = create_player()
- merr = 0
- perr = 0
- def jobM():
- nonlocal m, merr
- logger.info("Gathering Market Data.")
- try:
- m.fetchData()
- m.commit()
- logger.info("Market data gathering complete.")
- except Exception as e:
- logger.error(f"Market data gathering failed: {e}")
- merr += 1
- if merr >= 3:
- merr = 0
- m = create_market(login=args.login)
- def jobP():
- nonlocal p, perr
- logger.info("Gathering Player Data.")
- try:
- p.fetchData()
- p.commit()
- logger.info("Player data gathering complete.")
- except Exception as e:
- logger.error(f"Player data gathering failed: {e}")
- perr += 1
- if perr >= 3:
- perr = 0
- p = create_player()
- schedule.every(60).minutes.do(jobM)
- jobM()
- if args.player:
- schedule.every(60).minutes.do(jobP)
- jobP()
- try:
- while True:
- schedule.run_pending()
- time.sleep(1)
- except KeyboardInterrupt:
- logger.info("Script terminated by user.")
- sys.exit()
- if __name__ == "__main__":
- main()
|