<commit_before>import datetime
import argparse

from django.utils import timezone
from django.core.management.base import BaseCommand

from ...models import SentNotification


def valid_date(s):
    try:
        return datetime.datetime.strptime(s, "%Y-%m-%d")
    except ValueError:
        msg = "Not a valid date: '{0}'.".format(s)
        raise argparse.ArgumentTypeError(msg)


class Command(BaseCommand):
    help = 'Deletes notifications between the date ranges specified.'

    def add_arguments(self, parser):
        parser.add_argument('--start', help="includes this date, format YYYY-MM-DD", type=valid_date)
        parser.add_argument('--end', help="up to this date, format YYYY-MM-DD", type=valid_date)

    def handle(self, *args, **options):
        today = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)
        start_date = options['start'].date() if options['start'] else today
        end_date = options['end'].date() if options['end'] else today + datetime.timedelta(days=1)
        deleted_notifications = SentNotification.objects.filter(date_sent__range=[start_date, end_date]).delete()
        deleted_num = deleted_notifications[0] if deleted_notifications is not None else SentNotification.objects.filter(date_sent__range=[start_date, end_date]).count()
        self.stdout.write('Successfully deleted {num} notification(s)'.format(num=deleted_num))
<commit_msg>Actually fixed this now by calling it at the right time<commit_after>import datetime
import argparse

from django.utils import timezone
from django.core.management.base import BaseCommand

from ...models import SentNotification


def valid_date(s):
    try:
        return datetime.datetime.strptime(s, "%Y-%m-%d")
    except ValueError:
        msg = "Not a valid date: '{0}'.".format(s)
        raise argparse.ArgumentTypeError(msg)


class Command(BaseCommand):
    help = 'Deletes notifications between the date ranges specified.'

    def add_arguments(self, parser):
        parser.add_argument('--start', help="includes this date, format YYYY-MM-DD", type=valid_date)
        parser.add_argument('--end', help="up to this date, format YYYY-MM-DD", type=valid_date)

    def handle(self, *args, **options):
        today = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)
        start_date = options['start'].date() if options['start'] else today
        end_date = options['end'].date() if options['end'] else today + datetime.timedelta(days=1)
        qs = SentNotification.objects.filter(date_sent__range=[start_date, end_date])
        deleted_notifications = qs.delete()
        deleted_num = deleted_notifications[0] if deleted_notifications is not None else qs.count()
        self.stdout.write('Successfully deleted {num} notification(s)'.format(num=deleted_num))

{'fraction_non_alphanumeric': 0.12303851640513552, 'fraction_numerical': 0.004992867332382311, 'mean_word_length': 4.165745856353591, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4924869', 'n_tokens_mistral': 825, 'n_tokens_neox': 813, 'n_words': 209}