gatherMarket.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from market import Market
  2. from player import Player
  3. import schedule
  4. import time
  5. from datetime import datetime
  6. from logger import logger
  7. from config import Config
  8. # Set Config Parameters
  9. MARKET_POLL_INTERVAL = Config["gather"].get("MarketPollInterval",15)
  10. PLAYER_POLL_INTERVAL = Config["gather"].get("PlayerPollInterval",15)
  11. CollectPlayerData = Config["gather"].get("CollectPlayer",False)
  12. Login = Config["gather"].get("Login",False)
  13. # Handle command arguments
  14. import argparse
  15. parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,description="",epilog="")
  16. parser.add_argument(
  17. "-p",
  18. "--player",
  19. metavar="yes/no",
  20. choices=['yes','no'],
  21. help="Collect player data?"
  22. )
  23. parser.add_argument(
  24. "-l",
  25. "--login",
  26. metavar="yes/no",
  27. choices=['yes','no'],
  28. help="Login to Browser?"
  29. )
  30. args = parser.parse_args()
  31. if args.player is not None:
  32. if args.player == 'yes': CollectPlayerData = True
  33. else: CollectPlayerData = False
  34. login_yesno = args.login
  35. if args.login is not None:
  36. if args.login == 'yes': Login = True
  37. else: Login = False
  38. m=Market(login=Login)
  39. p=Player()
  40. merr=0
  41. perr=0
  42. def jobM():
  43. global m,merr
  44. logger.info("Gathering Market Data.")
  45. try:
  46. m.fetchData()
  47. m.commit()
  48. logger.info("Complete.")
  49. except Exception as e:
  50. logger.error(f"{e}")
  51. merr +=1
  52. if merr >= 3:
  53. merr=0
  54. m=Market()
  55. def jobP():
  56. global p,perr
  57. logger.info("Gathering Player Data.")
  58. try:
  59. p.fetchData()
  60. p.commit()
  61. logger.info("Complete.")
  62. except Exception as e:
  63. logger.error(f"{e}")
  64. perr +=1
  65. if perr >= 3:
  66. perr=0
  67. p=Player()
  68. schedule.every(MARKET_POLL_INTERVAL).minutes.do(jobM)
  69. jobM()
  70. if CollectPlayerData == 'yes':
  71. schedule.every(PLAYER_POLL_INTERVAL).minutes.do(jobP)
  72. jobP()
  73. while 1:
  74. schedule.run_pending()
  75. time.sleep(1)