How to use tempora - 10 common examples

To help you get started, we’ve selected a few tempora examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yougov / pmxbot / tests / functional / __init__.py View on Github external
def wait_for_tables(cls, timeout=30):
        watch = tempora.timing.Stopwatch()
        while watch.split() < datetime.timedelta(seconds=timeout):
            try:
                cls.check_logs('#check')
                return
            except Exception:
                # short-circuit if the bot has stopped
                if cls.bot.poll() is not None:
                    return
                time.sleep(0.2)
github yougov / pmxbot / tests / unit / test_core.py View on Github external
def __eq__(self, other):
        return isinstance(other, DelayedCommand)
github yougov / pmxbot / tests / unit / test_core.py View on Github external
def handler(self):
        return AtHandler(
            name='some name',
            channel='#some-channel',
            when=now(),
            func=lambda x: x,
            doc='some doc',
        )
github yougov / pmxbot / pmxbot / irc.py View on Github external
def _expired(self, last, now):
        return now - last > self.warn_every

    def warn(self, nick, connection):
        if pmxbot.config.get('privacy warning') == 'suppress':
            return
        if not self.needs_warning(nick):
            return
        logged_channels_string = ', '.join(pmxbot.config.log_channels)
        msg = self.warn_message.format(**locals())
        for line in msg.splitlines():
            connection.notice(nick, line)


class Scheduler(tempora.schedule.CallbackScheduler, irc.schedule.DefaultScheduler):
    pass


class LoggingCommandBot(core.Bot, irc.bot.SingleServerIRCBot):
    def __init__(self, server, port, nickname, channels, password=None):
        ErrorReportingBuffer.install()
        server_list = [(server, port, password)]
        super().__init__(server_list, nickname, nickname)
        self.reactor.scheduler = Scheduler(dispatch=self.handle_scheduled)
        self.nickname = nickname
        self._channels = channels
        self._nickname = nickname
        self.warn_history = WarnHistory()

    def connect(self, *args, **kwargs):
        factory = irc.connection.Factory(wrapper=self._get_wrapper())
github pajbot / pajbot / pajbot / eventloop.py View on Github external
def execute_every(self, period, func):
        self.add(schedule.PeriodicCommand.after(period, func))
github jaraco / irc / irc / schedule.py View on Github external
def execute_after(self, delay, func):
        self.add(schedule.DelayedCommand.after(delay, func))
github yougov / pmxbot / pmxbot / core.py View on Github external
def as_cmd(self):
        cls = schedule.PeriodicCommand if self.repeat else schedule.DelayedCommand
        return cls.after(self.duration, self)
github yougov / pmxbot / pmxbot / core.py View on Github external
def as_cmd(self):
        factory = (
            schedule.PeriodicCommandFixedDelay.daily_at
            if isinstance(self.when, datetime.time)
            else schedule.DelayedCommand.at_time
        )
        return factory(self.when, self)
github yougov / pmxbot / pmxbot / slack.py View on Github external
def __init__(self, server, port, nickname, channels, password=None):
        token = pmxbot.config['slack token']
        sc = importlib.import_module('slackclient')
        self.slack = sc.SlackClient(token)
        sr = importlib.import_module('slacker')
        self.slacker = sr.Slacker(token)

        self.scheduler = schedule.CallbackScheduler(self.handle_scheduled)
github jaraco / irc / irc / schedule.py View on Github external
"execute func every period"

    @abc.abstractmethod
    def execute_at(self, when, func):
        "execute func at when"

    @abc.abstractmethod
    def execute_after(self, delay, func):
        "execute func after delay"

    @abc.abstractmethod
    def run_pending(self):
        "invoke the functions that are due"


class DefaultScheduler(schedule.InvokeScheduler, IScheduler):
    def execute_every(self, period, func):
        self.add(schedule.PeriodicCommand.after(period, func))

    def execute_at(self, when, func):
        self.add(schedule.DelayedCommand.at_time(when, func))

    def execute_after(self, delay, func):
        self.add(schedule.DelayedCommand.after(delay, func))