script_task.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from tasks.Restart.config_scheduler import Scheduler
  5. from tasks.Restart.login import LoginHandler
  6. from tasks.Restart.assets import RestartAssets
  7. from tasks.base_task import BaseTask, Time
  8. from datetime import datetime, time
  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. self.app_restart()
  18. raise TaskEnd('ScriptTask end')
  19. def app_stop(self):
  20. logger.hr('App stop')
  21. self.device.app_stop()
  22. def app_start(self):
  23. logger.hr('App start')
  24. self.device.app_start()
  25. self.app_handle_login()
  26. # self.ensure_no_unfinished_campaign()
  27. def app_restart(self):
  28. logger.hr('App restart')
  29. self.device.app_stop()
  30. self.device.app_start()
  31. self.app_handle_login()
  32. # self.config.task_delay(server_update=True)
  33. self.set_next_run(task='Restart', success=True, finish=True, server=True)
  34. # 如果启用了定时领体力(每天 12-14、20-22 时内各有 20 体力)
  35. if self.config.restart.harvest_config.enable_ap:
  36. now = datetime.now()
  37. # 如果时间在00:00-12:00之间则设定时间为当日 12 时
  38. if now.time() < time(12, 0):
  39. self.custom_next_run(task='Restart', custom_time=Time(12, 0), time_delta=0)
  40. # 如果时间在12:00-20:00之间则设定时间为当日 20 时
  41. elif now.time() >= time(12, 0) and now.time() < time(20, 0):
  42. self.custom_next_run(task='Restart', custom_time=Time(20, 0), time_delta=0)
  43. # 如果时间在20:00-23:59之间则设定时间为次日 12 时
  44. else:
  45. self.custom_next_run(task='Restart', custom_time=Time(12, 0), time_delta=1)
  46. if __name__ == '__main__':
  47. from module.config.config import Config
  48. from module.device.device import Device
  49. config = Config('oas1')
  50. device = Device(config)
  51. task = ScriptTask(config, device)
  52. task.app_restart()
  53. # task.screenshot()
  54. # print(task.appear_then_click(task.I_LOGIN_SCROOLL_CLOSE, threshold=0.9))