import re, os, sys
from datetime import datetime, timedelta

from django.db.models import Count

import django
sys.path.append('../')
os.environ['DJANGO_SETTINGS_MODULE'] = 'ds_events.settings'
django.setup()

from events.models import Event, Organization

new_time = datetime.now() - timedelta(days=1)
right_bound_time = datetime.now() + timedelta(days=45)
events = Event.objects.filter(show_date__lte=new_time)
events1 = Event.objects.filter(show_date__gte=right_bound_time)

for e in events:
    e.delete()

for e in events1:
    e.delete()

org_sin_events = Organization.objects.annotate(num_events = Count('event')).filter(num_events__lt=1).filter(is_501c=False)

for org in org_sin_events:
    print(org)
    org.delete()

print("completed and cleaned scrapes")