Source

lindyjam / standalone / djschedule_remind.py

Full commit
#!/usr/local/bin/python2.5

import re, sys, os, datetime

sys.path.append('/home/sjl/webapps/lindyjam')
sys.path.append('/home/sjl/webapps/lindyjam/lib/python2.5/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'lindyjam.settings'

from lindyjam.djschedule.models import Slot
from lindyjam.sms.models import Carrier
from send_email import send_reminder
from lindyjam import deploy

USER = 'reminder'
PASS = deploy.REMINDER_PASS
FROM = 'reminder@lindyjam.com'
SMS_SUBJECT = ''
EMAIL_SUBJECT = 'Lindy Jam DJ reminder'
REMINDER = "Don't forget: you've signed up to DJ at Lindy Jam tonight at 8:30 PM!"

digits = re.compile(r'\d+')
today = datetime.date.today()
now = datetime.datetime.now()

try:
    slot_today = Slot.objects.get(dj_date__year=today.year, 
                                  dj_date__month=today.month,
                                  dj_date__day=today.day, 
                                  approved=True)
except Slot.DoesNotExist:
    print now, "No one signed up for today.  Not sending any reminders."
else:
    print now, "Someone is signed up to DJ. Reminders may be sent."
    phone = ''.join(digits.findall(slot_today.phone))
    postfix = slot_today.carrier.email_postfix if slot_today.carrier else None
    if (len(phone) == 10 and postfix):
        phone_address = "%s@%s" % (phone, postfix)
        send_reminder(phone_address, FROM, SMS_SUBJECT, REMINDER, USER, PASS)
        print now, "Sent %s an SMS reminder." % (phone_address, )
    
    email = slot_today.email
    if (len(email.strip()) > 0 and '@' in email):
        send_reminder(email, FROM, EMAIL_SUBJECT, REMINDER, USER, PASS)
        print now, "Sent %s an email reminder." % (email, )

#eof