def cleanup(days=30, tags=None):
    from sentry.models import Group, Event
    import datetime
    
    ts = datetime.datetime.now() - datetime.timedelta(days=days)
    
    for event in Event.objects.order_by('date'):
        if event.date > ts:
            break
        event.delete()
    
    for group in Group.objects.order_by('last_seen'):
        if group.last_seen > ts:
            break
        event.delete()
dataset/ETHPy150Open dcramer/sentry-old/sentry/web/scripts/runner.py/cleanup/original