<commit_before>"""Delta report management."""
import datetime


import main
db = main.db


REGISTER_UPDATE_DATE = datetime.datetime(1970, 1, 1)


def oldest(min_age=86400):
    """ Return the oldest delta that hasn't been updated for more than
    min_age.

    Return None if all deltas are up to date.

    min_age is in seconds, defaults to 24 hours.
    """
    age_delta = datetime.timedelta(seconds=min_age)
    try:
        domain, generated = db.deltas.oldest()
        if datetime.datetime.now() - generated > age_delta:
            return domain
        else:
            print 'No domains to resolve for approx {} seconds'.format(
                int(age_delta - (datetime.datetime.now() - generated))
            )
    except TypeError:
        # No deltas yet
        pass


def update(domain, deltas, generated=None):
    """Update the delta for a domain.

    Args:
        domain: the domain (as string) being reported on
        new, updated, deleted: the delta info
        generated: when the report was generated. Defaults to now.
    """
    if generated is None:
        generated = datetime.datetime.now()
    db.deltas.set(domain, deltas, generated)


def get(domain):
    """Return the deltas for a domain, or None if one hasn't been created yet.
    """
    return db.deltas.get(domain)


def register(domain):<commit_msg>Fixed delta logging<commit_after>"""Delta report management."""
import datetime


import main
db = main.db


REGISTER_UPDATE_DATE = datetime.datetime(1970, 1, 1)


def oldest(min_age=86400):
    """ Return the oldest delta that hasn't been updated for more than
    min_age.

    Return None if all deltas are up to date.

    min_age is in seconds, defaults to 24 hours.
    """
    age_delta = datetime.timedelta(seconds=min_age)
    try:
        domain, generated = db.deltas.oldest()
        if datetime.datetime.now() - generated > age_delta:
            return domain

        print 'No domains to resolve for approx {} seconds'.format(
            age_delta - int(datetime.datetime.now() - generated)
        )

    except TypeError:
        # No deltas yet
        pass


def update(domain, deltas, generated=None):
    """Update the delta for a domain.

    Args:
        domain: the domain (as string) being reported on
        new, updated, deleted: the delta info
        generated: when the report was generated. Defaults to now.
    """
    if generated is None:
        generated = datetime.datetime.now()
    db.deltas.set(domain, deltas, generated)


def get(domain):
    """Return the deltas for a domain, or None if one hasn't been created yet.
    """
    return db.deltas.get(domain)


def register(domain):
{'fraction_non_alphanumeric': 0.0930493273542601, 'fraction_numerical': 0.009715994020926755, 'mean_word_length': 2.578877005347594, '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': '72648', 'n_tokens_mistral': 805, 'n_tokens_neox': 761, 'n_words': 274}