<commit_before>from jinja2 import nodes
from jinja2.ext import Extension
from jinja2.utils import contextfunction, import_string, Markup
from commands import Action
import re
import datetime

class MailpileCommand(Extension):
    """Run Mailpile Commands, """
    tags = set(['mpcmd'])

    def __init__(self, environment):
        Extension.__init__(self, environment)
        self.env = environment
        environment.globals['mailpile'] = self._command
        environment.globals['regex_replace'] = self._regex_replace
        environment.globals['friendly_date'] = self._friendly_date

    def _command(self, command, *args, **kwargs):
        return Action(self.env.session, command, args, data=kwargs).as_dict()

    def _regex_replace(self, s, find, replace):
        """A non-optimal implementation of a regex filter"""
        return re.sub(find, replace, s)

    def _friendly_date(self, timestamp):
        days_ago = (datetime.datetime.now() - datetime.datetime.fromtimestamp(timestamp)) / (24*3600)

        if days_ago < 1:
            return 'today'
        elif days_ago < 2:
            return 'yesterday'
        elif days_ago < 7:
            return '%d days ago' % days_ago
        else:
            return timestamp.strftime("%Y-%m-%d")<commit_msg>Fixed friendly_date!<commit_after>from jinja2 import nodes
from jinja2.ext import Extension
from jinja2.utils import contextfunction, import_string, Markup
from commands import Action
import re
import datetime

class MailpileCommand(Extension):
    """Run Mailpile Commands, """
    tags = set(['mpcmd'])

    def __init__(self, environment):
        Extension.__init__(self, environment)
        self.env = environment
        environment.globals['mailpile'] = self._command
        environment.globals['regex_replace'] = self._regex_replace
        environment.globals['friendly_date'] = self._friendly_date
        environment.filters['friendly_date'] = self._friendly_date

    def _command(self, command, *args, **kwargs):
        return Action(self.env.session, command, args, data=kwargs).as_dict()

    def _regex_replace(self, s, find, replace):
        """A non-optimal implementation of a regex filter"""
        return re.sub(find, replace, s)

    def _friendly_date(self, timestamp):
        days_ago = (datetime.date.today() - datetime.date.fromtimestamp(timestamp)).days

        if days_ago < 1:
            return 'today'
        elif days_ago < 2:
            return 'yesterday'
        elif days_ago < 7:
            return '%d days ago' % days_ago
        else:
            return timestamp.strftime("%Y-%m-%d")
{'fraction_non_alphanumeric': 0.107952362658471, 'fraction_numerical': 0.006915097963887821, 'mean_word_length': 3.062402496099844, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '5973140', 'n_tokens_mistral': 749, 'n_tokens_neox': 710, 'n_words': 193}