root / cron_notify_expired.py @ fd3870ee
History | View | Annotate | Download (1.1 kB)
1 |
from django.core.management import setup_environ |
---|---|
2 |
import settings |
3 |
setup_environ(settings) |
4 |
from django.core.mail import send_mail |
5 |
from flowspy.flowspec.models import * |
6 |
from django.template.loader import render_to_string |
7 |
import datetime |
8 |
|
9 |
|
10 |
def notify_expired(): |
11 |
routes = Route.objects.all() |
12 |
for route in routes: |
13 |
if route.status != 'EXPIRED': |
14 |
expiration_days = (route.expires - datetime.date.today()).days |
15 |
if expiration_days < settings.EXPIRATION_NOTIFY_DAYS:
|
16 |
try:
|
17 |
mail_body = render_to_string("rule_expiration.txt",
|
18 |
{"route": route, 'expiration_days':expiration_days}) |
19 |
send_mail(settings.EMAIL_SUBJECT_PREFIX + "Rule %s expires in %s days" %
|
20 |
(route.name,expiration_days), |
21 |
mail_body, settings.SERVER_EMAIL, |
22 |
[route.applier.email]) |
23 |
except Exception as e: |
24 |
print e
|
25 |
pass
|
26 |
|
27 |
if __name__ == "__main__": |
28 |
notify_expired() |
29 |
|