Skip to content

Commit

Permalink
Management command to be run from cron and send email alerts about ex…
Browse files Browse the repository at this point in the history
…piring domains
  • Loading branch information
damianmoore committed Nov 2, 2014
1 parent a6c490d commit e6b867e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions domaintools/management/commands/notify_expiry.py
@@ -0,0 +1,23 @@
from django.conf import settings
from django.core.mail import send_mail
from django.core.management.base import BaseCommand, CommandError

from domaintools.models import Domain


ALERT_SEND_DAYS = [14, 3, 1]


class Command(BaseCommand):
help = 'Sends notifications by email when domains are going to expire.'

def handle(self, *args, **options):
for domain in Domain.objects.all():
days_remaining = domain.days_remaining()
if days_remaining < max(ALERT_SEND_DAYS):
print 'Domain {} expires in {} days'.format(domain.id, domain.days_remaining())
if days_remaining in ALERT_SEND_DAYS:
send_mail('Domain Expiring: {}'.format(domain.id),
'The domain {} is going to expire on {} ({} days)'.format(domain.id, domain.expiry_date, days_remaining),
'webmaster@epixstudios.co.uk',
[admin[1] for admin in settings.ADMINS])

0 comments on commit e6b867e

Please sign in to comment.