__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. """Resource tracker"""
  2. import os
  3. import logging
  4. from dotenv import load_dotenv
  5. from apscheduler.schedulers.background import BackgroundScheduler
  6. from rival_regions_wrapper.rival_regions_wrapper import Client
  7. load_dotenv()
  8. SCHEDULER = BackgroundScheduler(
  9. daemon=True,
  10. job_defaults={'misfire_grace_time': 300},
  11. )
  12. SCHEDULER.start()
  13. # logger
  14. LOGGER = logging.getLogger('resource_tracker')
  15. LOGGER.setLevel(logging.DEBUG)
  16. # scheduler logger
  17. SCHEDULER_LOGGER = logging.getLogger('apscheduler')
  18. SCHEDULER_LOGGER.setLevel(logging.DEBUG)
  19. # RR wrapper logger
  20. RR_WRAPPER_LOGGER = logging.getLogger('rival_regions_wrapper')
  21. RR_WRAPPER_LOGGER.setLevel(logging.DEBUG)
  22. # create file handler
  23. FILE_HANDLER = logging.FileHandler('output.log')
  24. FILE_HANDLER.setLevel(logging.DEBUG)
  25. # create console handler
  26. STREAM_HANDLER = logging.StreamHandler()
  27. STREAM_HANDLER.setLevel(logging.INFO)
  28. # create formatter and add it to the handlers
  29. FORMATTER = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  30. STREAM_HANDLER.setFormatter(FORMATTER)
  31. FILE_HANDLER.setFormatter(FORMATTER)
  32. # add the handlers to logger
  33. LOGGER.addHandler(STREAM_HANDLER)
  34. LOGGER.addHandler(FILE_HANDLER)
  35. SCHEDULER_LOGGER.addHandler(STREAM_HANDLER)
  36. SCHEDULER_LOGGER.addHandler(FILE_HANDLER)
  37. RR_WRAPPER_LOGGER.addHandler(STREAM_HANDLER)
  38. RR_WRAPPER_LOGGER.addHandler(FILE_HANDLER)
  39. RR_WRAPPER = Client(show_window=os.environ['SHOW_WINDOW'].lower() == 'true')
  40. RR_WRAPPER.set_credentials({
  41. 'login_method': os.environ['LOGIN_METHOD'],
  42. 'username': os.environ['USERNAME'],
  43. 'password': os.environ['PASSWORD']
  44. })
  45. STATE_ID = os.environ['STATE_ID']
  46. CAPITAL_ID = os.environ['CAPITAL_ID']
  47. RESOURCE_IDS = {
  48. 0: 'gold',
  49. 3: 'oil',
  50. 4: 'ore',
  51. 11: 'uranium',
  52. 15: 'diamond',
  53. }
  54. RESOURCE_NAMES = {
  55. 'gold': 0,
  56. 'oil': 3,
  57. 'ore': 4,
  58. 'uranium': 11,
  59. 'diamond': 15,
  60. }
  61. RESOURCE_MAX = {
  62. 0: 2500,
  63. 3: 600,
  64. 4: 500,
  65. 11: 60,
  66. 15: 75,
  67. }