<commit_before>import datetime

from django.core.management.base import BaseCommand, CommandError

from clowder_server.emailer import send_alert
from clowder_server.models import Alert

class Command(BaseCommand):
    help = 'Checks and sends alerts'

    def handle(self, *args, **options):
        alerts = Alert.objects.filter(notify_at__lte=datetime.datetime.now)
        for alert in alerts:
            send_alert(request.user, alert.name)
            alert.notify_at = None
            alert.save()
<commit_msg>Delete old unused pings from users<commit_after>import datetime

from django.core.management.base import BaseCommand, CommandError

from clowder_account.models import ClowderUser
from clowder_server.emailer import send_alert
from clowder_server.models import Alert, Ping

class Command(BaseCommand):
    help = 'Checks and sends alerts'

    def handle(self, *args, **options):

        # delete old pings
        for user in ClowderUser.objects.all():
            pings = Ping.objects.filter(user=user)[:500]
            pings = list(pings) # forces database hit
            Ping.objects.exclude(pk__in=pings).delete()

        # send alerts
        alerts = Alert.objects.filter(notify_at__lte=datetime.datetime.now)
        for alert in alerts:
            send_alert(request.user, alert.name)
            alert.notify_at = None
            alert.save()

{'fraction_non_alphanumeric': 0.0829090909090909, 'fraction_numerical': 0.002181818181818182, 'mean_word_length': 3.083086053412463, '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': '4620142', 'n_tokens_mistral': 405, 'n_tokens_neox': 390, 'n_words': 101}