__main__.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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(2788, 4002, 0)
  7. # jobs.check_resources(2788, 4002, 0, True) # VN
  8. # jobs.check_resources(2620, 4002, 0, False) # Zeelandiae
  9. # graph()
  10. # get_resources(4001, datetime.now(), 0)
  11. JOBS = job_storage.get_jobs()
  12. for job in JOBS:
  13. LOGGER.info(
  14. 'Add check for "%s", resource "%s" at "%s"',
  15. job['state_id'],
  16. job['resource_type'],
  17. job['minutes']
  18. )
  19. SCHEDULER.add_job(
  20. jobs.check_resources,
  21. 'cron',
  22. args=[
  23. job['state_id'],
  24. job['capital_id'],
  25. RESOURCE_NAMES[job['resource_type']],
  26. job['refill']
  27. ],
  28. id='{}_check_{}'.format(job['state_id'], job['resource_type']),
  29. replace_existing=True,
  30. minute=job['minutes']
  31. )
  32. SCHEDULER.add_job(
  33. jobs.send_telegram_update,
  34. 'cron',
  35. args=[2788, '@vn_resources', 0],
  36. id='send_telegram_update',
  37. replace_existing=True,
  38. minute='5'
  39. )
  40. try:
  41. while True:
  42. time.sleep(100)
  43. except KeyboardInterrupt:
  44. LOGGER.info('Exiting application')
  45. SCHEDULER.shutdown()
  46. sys.exit()