script_task.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from datetime import datetime
  5. from tasks.Restart.config_scheduler import Scheduler
  6. from tasks.Restart.login import LoginHandler
  7. from tasks.Restart.assets import RestartAssets
  8. from tasks.base_task import BaseTask
  9. from module.logger import logger
  10. from module.exception import TaskEnd, RequestHumanTakeover
  11. class ScriptTask(LoginHandler):
  12. def run(self) -> None:
  13. """
  14. 主要就是登录的模块
  15. :return:
  16. """
  17. if not self.delay_pending_tasks():
  18. self.app_restart()
  19. raise TaskEnd('ScriptTask end')
  20. def app_stop(self):
  21. logger.hr('App stop')
  22. self.device.app_stop()
  23. def app_start(self):
  24. logger.hr('App start')
  25. self.device.app_start()
  26. self.app_handle_login()
  27. # self.ensure_no_unfinished_campaign()
  28. def app_restart(self):
  29. logger.hr('App restart')
  30. self.device.app_stop()
  31. self.device.app_start()
  32. self.app_handle_login()
  33. # self.config.task_delay(server_update=True)
  34. self.set_next_run(task='Restart', success=True, finish=True, server=True)
  35. def delay_pending_tasks(self) -> bool:
  36. """
  37. 周三更新游戏的时候延迟
  38. @return:
  39. """
  40. datetime_now = datetime.now()
  41. if not (datetime_now.weekday() == 2 and 6 <= datetime_now.hour <= 8):
  42. return False
  43. logger.info("The game server is updating, delay the pending tasks to 9:00")
  44. logger.warning('Delay pending tasks')
  45. # running 中的必然是 Restart
  46. for task in self.config.pending_task:
  47. print(task.command)
  48. self.set_next_run(task=task.command, target=datetime_now.replace(hour=9, minute=0, second=0, microsecond=0))
  49. return True
  50. if __name__ == '__main__':
  51. from module.config.config import Config
  52. from module.device.device import Device
  53. config = Config('oas1')
  54. device = Device(config)
  55. task = ScriptTask(config, device)
  56. task.config.update_scheduler()
  57. task.delay_pending_tasks()
  58. # task.screenshot()
  59. # print(task.appear_then_click(task.I_LOGIN_SCROOLL_CLOSE, threshold=0.9))