Exemplo n.º 1
0
    def response(self, user, text, reply_to=None):
        self._scanner = ReminderScanner(text)
        response = "" 
        valid = True
        tweet_hash = hashlib.sha1()
        tweet_hash.update(text)
        tweet_hash = tweet_hash.hexdigest()[:6]

        try:
            self._reminder = self._scanner.extract()
        except:
            valid = False
            response += gs("PARSE_ERROR") 

            return self._split("@" + user, response, reply_to=reply_to) 

        if self._reminder.error != None:
            valid = False
            response += gs("ERROR_OCCURRED") % self._reminder.error
        elif self._reminder.timedelta == None:
            valid = False
            response += gs("NO_TIMEDELTA")
        elif self._reminder.text == None:
            response += gs("NO_REMINDER_TEXT") % tweet_hash
        if self._reminder.text != None and valid:
            response += gs("REMINDER_SET") % tweet_hash

        # Save the job in the scheduler
        if valid:
            j = Job(extra={'user': user}, payload=self._reminder)
            j.store(r)

        return self._split("@" + user, response, reply_to=reply_to) 
Exemplo n.º 2
0
def run():
    logger.debug("Scheduler thread started")
    while True:
        now = datetime.now()
        ts = int(time.mktime(now.timetuple()))
        jobs = r.zrangebyscore("jobs", "-inf", ts)

        if len(jobs):
            for job in jobs:
                Job.from_config_key(r, job).execute(r)
                r.zrem("jobs", job)
            logger.debug("Executed %d jobs" % len(jobs))

        time.sleep(1)