misc: on Fridays send emails for Sat and Sun and Mon (#9018)

This commit is contained in:
Frédéric Péters 2015-11-18 12:09:56 +01:00
parent aba220d7b6
commit 484826cfc1
1 changed files with 16 additions and 8 deletions

View File

@ -20,11 +20,19 @@ class Command(BaseCommand):
return requests.get(url, headers={'Accept': 'application/json'})
def handle(self, *args, **kwargs):
tomorrow = datetime.today() + timedelta(days=1)
filter_query = '?filter=all&filter-date=%s&full=on' % tomorrow.strftime('%Y-%m-%d')
url = getattr(settings, 'ENCOMBRANTS_FORM_URL') + filter_query
r = self.get(url, True)
if not 'err' in r.json():
email_sectors(r.json(), tomorrow)
else:
raise CommandError('Error while retreiving formdefs: %s' % r.json())
if datetime.date.today().weekday() in (5, 6):
# we don't notify during the weekend
return
tomorrows = [datetime.today() + timedelta(days=1)]
if datetime.date.today().weekday() == 4:
# on Fridays we also notify about Sundays (just to be sure) and Mondays
tomorrows.append(datetime.today() + timedelta(days=2))
tomorrows.append(datetime.today() + timedelta(days=3))
for tomorrow in tomorrows:
filter_query = '?filter=all&filter-date=%s&full=on' % tomorrow.strftime('%Y-%m-%d')
url = getattr(settings, 'ENCOMBRANTS_FORM_URL') + filter_query
r = self.get(url, True)
if not 'err' in r.json():
email_sectors(r.json(), tomorrow)
else:
raise CommandError('Error while retrieving formdefs: %s' % r.json())