gatherMarket.py 1.5 KB

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