<commit_before>#! /usr/bin/python
import logging
from datetime import datetime
from itertools import ifilter

import settings
from model import User, Task
from library.template import Template
from library.mailclient import MailClient, Subjects


class Cron(object):
    def __init__(self):
        self.now = datetime.now()
        self.template = Template()
        self.mailclient = MailClient()

        if settings.DEBUG:
            self.mail_buffer = []

    def job(self):
        users = User.select().where(User.is_active == True)
        print "Users: " + [user.name for user in users]
        for user in ifilter(lambda user: user.is_due(self.now), users):
            print "Creating digest for {0}".format(user.name)
            try:
                digest = self.create_digest(user)
                print "Successfully created digest for {0}".format(user.name)
                email = self.mailclient.send(user, digest, Subjects.DIGEST)
                print "Sent digest to {0}".format(user.name)
            except:
                print "Couldn't send digest to {0}".format(user.name)
                logging.error("Failed to send email to {0}".format(user.name))
                if settings.DEBUG:
                    raise

            if settings.DEBUG:
                print user.name
                print email, '\n\n'
            else:
                user.last_sent = self.now
                user.save()

    def create_digest(self, user):
        last_sent = user.last_sent or user.created
        tasks = Task.select()\
            .where((Task.date > last_sent))\
            .order_by(Task.user.name, Task.date)<commit_msg>Added more debugging:<commit_after>#! /usr/bin/python
import logging
from datetime import datetime
from itertools import ifilter

import settings
from model import User, Task
from library.template import Template
from library.mailclient import MailClient, Subjects


class Cron(object):
    def __init__(self):
        print "Construction cron object"
        self.now = datetime.now()
        print "Determined current time"
        self.template = Template()
        print "Created template manager"
        self.mailclient = MailClient()
        print "Created mail client"
        print "Finished constructing cron Object"

    def job(self):
        pring "Getting users"
        users = User.select().where(User.is_active == True)
        print "Users: " + [user.name for user in users]
        for user in ifilter(lambda user: user.is_due(self.now), users):
            print "Creating digest for {0}".format(user.name)
            try:
                digest = self.create_digest(user)
                print "Successfully created digest for {0}".format(user.name)
                email = self.mailclient.send(user, digest, Subjects.DIGEST)
                print "Sent digest to {0}".format(user.name)
            except:
                print "Couldn't send digest to {0}".format(user.name)
                logging.error("Failed to send email to {0}".format(user.name))
                if settings.DEBUG:
                    raise

            if settings.DEBUG:
                print user.name
                print email, '\n\n'
            else:
                user.last_sent = self.now
                user.save()

    def create_digest(self, user):
        last_sent = user.last_sent or user.created
        tasks = Task.select()\
            .where((Task.date > last_sent))\
            .order_by(Task.user.name, Task.date)
{'fraction_non_alphanumeric': 0.09822451317296678, 'fraction_numerical': 0.0028636884306987398, 'mean_word_length': 1.937762825904121, 'pattern_counts': {'":': 0, '<': 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': '2777256', 'n_tokens_mistral': 975, 'n_tokens_neox': 917, 'n_words': 268}