task.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from time import sleep
  5. from datetime import datetime, time
  6. from random import randint
  7. from module.config.config import Config
  8. class Task:
  9. def __init__(self,
  10. next_run: datetime,
  11. limit_time: time,
  12. target_run: datetime = None,
  13. team_task: bool = False,
  14. role: str = 'leader',
  15. limit_count: int = 0,
  16. ):
  17. self.next_run = next_run
  18. self.target_run = target_run
  19. self.limit_time = limit_time
  20. self.team_task = team_task
  21. self.role = role
  22. self.limit_count = limit_count
  23. def update_info(self,
  24. next_run: datetime,
  25. limit_time: time,
  26. limit_count: int,
  27. role: str):
  28. # next_run
  29. if isinstance(next_run, datetime):
  30. self.next_run = next_run
  31. elif isinstance(next_run, str):
  32. self.next_run = datetime.fromisoformat(next_run)
  33. else:
  34. raise TypeError(f'next_run must be datetime or str, not {type(next_run)}')
  35. # limit_count
  36. if isinstance(limit_count, int):
  37. self.limit_count = limit_count
  38. elif isinstance(limit_count, str):
  39. self.limit_count = int(limit_count)
  40. else:
  41. raise TypeError(f'limit_count must be int or str, not {type(limit_count)}')
  42. # limit_time
  43. if isinstance(limit_time, time):
  44. self.limit_time = limit_time
  45. elif isinstance(limit_time, str):
  46. self.limit_time = time.fromisoformat(limit_time)
  47. else:
  48. raise TypeError(f'limit_time must be time or str, not {type(limit_time)}')
  49. # role
  50. if isinstance(role, str):
  51. self.role = role
  52. else:
  53. raise TypeError(f'role must be str, not {type(role)}')