__main__.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. """Main app"""
  2. import sys
  3. import time
  4. from app import SCHEDULER, LOGGER, jobs, job_storage
  5. def print_professors(professors):
  6. """Print professors"""
  7. for professor in professors:
  8. print('{:30} {:2} {:>25}'.format(
  9. professor['name'],
  10. professor['points'],
  11. professor['date_time'].strftime('%d %B %Y %H:%M'),
  12. ))
  13. def add_update_department(state_id, department_type):
  14. """Add jobs"""
  15. SCHEDULER.add_job(
  16. jobs.update_department,
  17. 'cron',
  18. args=[state_id, department_type],
  19. id='{}_{}'.format(state_id, department_type),
  20. replace_existing=True,
  21. hour='19'
  22. )
  23. def add_send_progress_message(state_id, department_type, language):
  24. """Add send_message"""
  25. SCHEDULER.add_job(
  26. jobs.send_progress_message,
  27. 'cron',
  28. args=[state_id, department_type, language],
  29. id='send_progress_message_{}_{}'.format(state_id, department_type),
  30. replace_existing=True,
  31. hour='19',
  32. minute='10'
  33. )
  34. def add_send_lotery_message(state_id, department_type, language, amount):
  35. """Add send_message"""
  36. SCHEDULER.add_job(
  37. jobs.send_lotery_message,
  38. 'cron',
  39. args=[state_id, department_type, language, amount],
  40. id='send_loter_message_{}_{}'.format(state_id, department_type),
  41. replace_existing=True,
  42. hour='8',
  43. )
  44. if __name__ == '__main__':
  45. # jobs
  46. # jobs.update_department(2788, 6)
  47. # jobs.send_progress_message(2788, 6, 'nl')
  48. # jobs.send_lotery_message(2788, 6, 'nl', 32e8)
  49. # sys.exit()
  50. # Jobs
  51. JOBS = job_storage.get_jobs()
  52. for job in JOBS:
  53. LOGGER.info(
  54. 'For "%s" add department "%s" update',
  55. job['state_id'],
  56. job['department_type']
  57. )
  58. SCHEDULER.add_job(
  59. jobs.update_department,
  60. 'cron',
  61. args=[job['state_id'], job['department_type']],
  62. id='{}_{}'.format(job['state_id'], job['department_type']),
  63. replace_existing=True,
  64. hour='19'
  65. )
  66. # progress message VN uranium
  67. add_send_progress_message(2788, 6, 'nl')
  68. add_send_lotery_message(2788, 6, 'nl', 36e8)
  69. try:
  70. while True:
  71. time.sleep(100)
  72. except KeyboardInterrupt:
  73. print('Exiting application')
  74. SCHEDULER.shutdown()
  75. sys.exit()