__main__.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """Main app"""
  2. import time
  3. import sys
  4. from app import SCHEDULER, LOGGER, RESOURCE_NAMES, job_storage, jobs#, app
  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, 4004, 0, True)
  17. # jobs.refill_resource(3261, 200062, 0, False)
  18. # jobs.check_resources(3304, 4004, 0, False, False) # VN
  19. # jobs.check_resources(3304, 4004, 3, False, False) # VN
  20. # jobs.check_resources(3304, 4004, 11, False, False) # VN
  21. # app.graph()
  22. # sys.exit()
  23. # get_resources(4001, datetime.now(), 0)
  24. # jobs.send_telegram_update(2788, '@vn_resources', 'gold')
  25. # jobs.send_telegram_update(2788, '@vn_uranium_resources', 'uranium')
  26. # sys.exit()
  27. JOBS = job_storage.get_jobs()
  28. for job in JOBS:
  29. LOGGER.info(
  30. 'Add check for "%s", resource "%s" at "%s", alt "%s"',
  31. job['state_id'],
  32. job['resource_type'],
  33. job['minutes'],
  34. job['alt']
  35. )
  36. SCHEDULER.add_job(
  37. jobs.check_resources,
  38. 'cron',
  39. args=[
  40. job['state_id'],
  41. job['capital_id'],
  42. RESOURCE_NAMES[job['resource_type']],
  43. job['refill'],
  44. job['alt']
  45. ],
  46. id='{}_check_{}'.format(job['state_id'], job['resource_type']),
  47. replace_existing=True,
  48. minute=job['minutes']
  49. )
  50. add_telegram_update_job(3813, '@vn_resources', 'gold')
  51. add_telegram_update_job(3813, '@vn_uranium_resources', 'uranium')
  52. try:
  53. while True:
  54. time.sleep(100)
  55. except KeyboardInterrupt:
  56. LOGGER.info('Exiting application')
  57. SCHEDULER.shutdown()
  58. sys.exit()