__main__.py 1.9 KB

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