<commit_before>from rel import timeout
from cantools import config
from cantools.util import read
from ..util import do_respond

secsPerUnit = {
    "hours": 60 * 60,
    "minutes": 60,
    "mins": 60,
    "seconds": 1
}

class Rule(object):
    def __init__(self, controller, url, rule, logger_getter):
        self.logger = logger_getter("Rule(%s -> %s)"%(rule, url))
        self.controller = controller
        self.url = url
        self.rule = rule
        self.words = rule.split(" ")
        self.timer = timeout(None, self.trigger)
        self.parse()

    def trigger(self):
        self.logger.info("trigger: %s %s"%(self.url, self.seconds))
        self.controller.trigger_handler(self.url, self.url[1:])
        return True

    def start(self):
        self.logger.info("start (%s seconds)"%(self.seconds,))
        self.timer.add(self.seconds)

    def parse(self):
        self.logger.info("parse")
        if len(self.words) == 3 and self.words[0] == "every": # every [NUMBER] [UNIT]
            num = int(self.words[1])
            unit = self.words[2]
            self.seconds = num * secsPerUnit[unit]
        else: # we can implement more later...
            self.logger.error("can't parse: %s"%(self.line,))

class Cron(object):
    def __init__(self, controller, logger_getter):
        self.logger_getter = logger_getter
        self.logger = logger_getter("Cron")<commit_msg>dez (web) cron Rule: start() and parse() support "on start" rule<commit_after>from rel import timeout
from cantools import config
from cantools.util import read
from ..util import do_respond

secsPerUnit = {
    "hours": 60 * 60,
    "minutes": 60,
    "mins": 60,
    "seconds": 1
}

class Rule(object):
    def __init__(self, controller, url, rule, logger_getter):
        self.logger = logger_getter("Rule(%s -> %s)"%(rule, url))
        self.controller = controller
        self.url = url
        self.rule = rule
        self.words = rule.split(" ")
        self.timer = timeout(None, self.trigger)
        self.parse()

    def trigger(self):
        self.logger.info("trigger: %s %s"%(self.url, self.seconds))
        self.controller.trigger_handler(self.url, self.url[1:])
        return True

    def start(self):
        if self.words != "on start":
            self.logger.info("start (%s seconds)"%(self.seconds,))
            self.timer.add(self.seconds)

    def parse(self):
        self.logger.info("parse")
        if self.words == "on start":
            self.logger.info("triggering start script")
            self.trigger()
        elif len(self.words) == 3 and self.words[0] == "every": # every [NUMBER] [UNIT]
            num = int(self.words[1])
            unit = self.words[2]
            self.seconds = num * secsPerUnit[unit]
        else: # we can implement more later...
            self.logger.error("can't parse: %s"%(self.line,))

class Cron(object):
    def __init__(self, controller, logger_getter):
        self.logger_getter = logger_getter
        self.logger = logger_getter("Cron")
{'fraction_non_alphanumeric': 0.14228987425545997, 'fraction_numerical': 0.009265387160820648, 'mean_word_length': 2.4988425925925926, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4530156', 'n_tokens_mistral': 967, 'n_tokens_neox': 926, 'n_words': 229}