__main__.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """Main app"""
  2. import time
  3. import sys
  4. from app import SCHEDULER, LOGGER, RESOURCE_NAMES, job_storage, jobs
  5. if __name__ == '__main__':
  6. # jobs.refill_resource(3304, 2103, 0, True)
  7. # jobs.check_resources(2788, 4002, 0, True) # VN
  8. # jobs.check_resources(2620, 4002, 0, False) # Zeelandiae
  9. # app.graph()
  10. # get_resources(4001, datetime.now(), 0)
  11. # jobs.send_telegram_update(2788, '@vn_resources', 'gold')
  12. # jobs.send_telegram_update(2788, '@vn_uranium_resources', 'uranium')
  13. # sys.exit()
  14. JOBS = job_storage.get_jobs()
  15. for job in JOBS:
  16. LOGGER.info(
  17. 'Add check for "%s", resource "%s" at "%s", alt "%s"',
  18. job['state_id'],
  19. job['resource_type'],
  20. job['minutes'],
  21. job['alt']
  22. )
  23. SCHEDULER.add_job(
  24. jobs.check_resources,
  25. 'cron',
  26. args=[
  27. job['state_id'],
  28. job['capital_id'],
  29. RESOURCE_NAMES[job['resource_type']],
  30. job['refill'],
  31. job['alt']
  32. ],
  33. id='{}_check_{}'.format(job['state_id'], job['resource_type']),
  34. replace_existing=True,
  35. minute=job['minutes']
  36. )
  37. # VN gold
  38. SCHEDULER.add_job(
  39. jobs.send_telegram_update,
  40. 'cron',
  41. args=[2788, '@vn_resources', 'gold'],
  42. id='send_telegram_update',
  43. replace_existing=True,
  44. minute='5'
  45. )
  46. # VN uranium
  47. SCHEDULER.add_job(
  48. jobs.send_telegram_update,
  49. 'cron',
  50. args=[2788, '@vn_uranium_resources', 'uranium'],
  51. id='send_telegram_update',
  52. replace_existing=True,
  53. minute='5'
  54. )
  55. try:
  56. while True:
  57. time.sleep(100)
  58. except KeyboardInterrupt:
  59. LOGGER.info('Exiting application')
  60. SCHEDULER.shutdown()
  61. sys.exit()