A Telegram Userbot built on Pyrogram
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

interval.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # This class was created for combot and has been disclosed by Sergey
  2. # https://t.me/combotchat/45392
  3. import re
  4. class IntervalHelper(object):
  5. class IntervalError(Exception):
  6. pass
  7. interval_re = re.compile(r'^(\d+)(w|d|h|m)?$')
  8. def __init__(self, _interval):
  9. self._interval = _interval
  10. if not self.interval_ok():
  11. raise Exception("Invalid interval format.")
  12. def interval_ok(self):
  13. if IntervalHelper.interval_re.match(self._interval):
  14. return True
  15. return False
  16. def to_secs(self):
  17. m = IntervalHelper.interval_re.match(self._interval)
  18. num, unit = m.groups()
  19. num = int(num)
  20. if not unit:
  21. unit = 'm'
  22. if unit == 'm':
  23. return [num*60, num, "minute" if num == 1 else "minutes"]
  24. elif unit == 'h':
  25. return [num*60*60, num, "hour" if num == 1 else "hours"]
  26. elif unit == 'd':
  27. return [num*60*60*24, num, "day" if num == 1 else "days"]
  28. elif unit == 'w':
  29. return [num*60*60*24*7, num, "week" if num == 1 else "weeks"]
  30. interval = property(lambda self: self._interval)