コード例 #1
0
ファイル: reminder.py プロジェクト: eokyere/pactremind
 def handle_sms(self, message):
     phone_number = sanitize_number(message.sender)
     IncomingMessage(text=message.text,
                     sender=phone_number, 
                     received_at=message.received,
                     network=network(message.sender)).save()
     try:
         subject = Subject.objects.get(phone_number=phone_number)
     except:
         subject = None
     
     if not subject:
         self.register(phone_number, message.received)
     elif subject.active and message.text.lower().startswith('stop'):
         self.deactivate(subject)
     else:
         self.send(message.sender, 
                   settings.ALREADY_REGISTERED_MESSAGE)
コード例 #2
0
ファイル: reminder.py プロジェクト: eokyere/pactremind
 def register(self, phone_number, received_at=datetime.now()):
     if not phone_number.startswith('+'):
         phone_number = sanitize_number(phone_number)
     subject = Subject(phone_number=phone_number,
                       received_at=received_at,
                       messages_left=6)
     if len(Subject.objects.all()) % 2 >=0: #new
         subject.message_id = random.randint(0, 
                                             len(settings.MESSAGES) - 1)
     subject.save()            
     self.send(phone_number, 
               settings.REGISTRATION_SUCCESS_MESSAGE)
     today = datetime.today()
     cutoff = datetime(today.year, today.month, today.day, 15)
     if received_at < cutoff and subject.message_id: #new after and
         now  = datetime.now()
         def send_reminder_in_15():
             log.debug('Sending out task scheduled at: %s' % now)
             self.send_reminder(subject)
         self.scheduler.add_single_task(action=send_reminder_in_15,
                                        initialdelay=900, # 15 * 60 secs=900
                                        taskname='Send delayed first msg',
                                        processmethod=method.threaded,
                                        args=[], kw={})
コード例 #3
0
ファイル: reminder.py プロジェクト: eokyere/pactremind
 def handle_call(self, modem_id, caller, dt):
     phone_number = sanitize_number(caller)
     try:
         subject = Subject.objects.get(phone_number=phone_number)
     except:
         self.register(phone_number, dt)