def reschedule_reminder(self, *args, **kwargs): ndatetime = kwargs['response'] session_id = kwargs['session_id'] print 'in %s: user responsed with date: %s' % (self.__class__, kwargs['response']) print 'args: %s kwargs: %s' % (args, kwargs) print 'self.args: %s' % (self.args) pdt = parsedatetime.Calendar() (res, retval) = pdt.parse(ndatetime) if retval == 0: raise ValueError("Unable to parse date time: %s" % (ndatetime)) # get the first 6 values from teh stuct... the rest we do not care about t = datetime(*res[0:7]) # support cens gui: app_date used to display appointment time only # Tuesday, 5:30pm, November 03, 2010 appttime = t.strftime("%A %I:%M%p, %B %d, %Y") # make sure we pass on the appointment date self.args['appt_date'] = appttime print 'self.args: %s' % (self.args) # sched a reminder. d1 = {'task': 'Appointment Reminder','user': self.user.identity,'args': self.args,'schedule_date': t,'session_id': session_id} try: taskscheduler.schedule(d1) except Exception as e: print '%s' % (e)
def schedule_reminders(self, *args, **kwargs): # ndatetime = kwargs['response'] # FAISAL: we grab ndatetime from the args, which was populated in the check_valid_appt callback ndatetime = self.args['pending_datetime'] # also clear pending_datetime from the args collection so that we don't give it to our child events del self.args['pending_datetime'] session_id = kwargs['session_id'] print 'in %s: user responsed with date: %s' % (self.__class__, kwargs['response']) print 'args: %s kwargs: %s' % (args, kwargs) print 'self.args: %s' % (self.args) pdt = parsedatetime.Calendar() (res, retval) = pdt.parse(ndatetime) if retval == 0: raise ValueError("Unable to parse date time: %s" % (ndatetime)) # get the first 6 values from the stuct... the rest we do not care about t = datetime(*res[0:7]) #t = datetime.strptime(ndatetime, "%m/%d/%Y %H:%M:%S") s = timedelta(days=1) i = timedelta(microseconds=1) # support cens gui: appt_date used to display the appointment time only # FAISAL: changed the date output format b/c parsedatetime doesn't read past the day of the week :\ appttime = t.strftime("%m/%d/%Y %I:%M%p") # make sure we pass on the appointment date self.args['appt_date'] = appttime print 'self.args: %s' % (self.args) testing = False if testing: # easier to track msgs s = timedelta(seconds=120) # 5 minutes a = t+s # first reminder 5 minutes after datetime reply b = t+2*s # second is 10 minutes after c = t+3*s # third is 15 after f = t+4*s # follow sent 20 hour after else: # faisal: commented out the above; we're going to use parsedatetime instead for readability a = datetime(*pdt.parse("2 days ago at 3:00pm", t)[0][0:7]) # two days before b = datetime(*pdt.parse("1 day ago at 8:00pm", t)[0][0:7]) # one night before c = datetime(*pdt.parse("2 hours ago", t)[0][0:7]) # two hours before appointment f = datetime(*pdt.parse("in 6 hours", t)[0][0:7]) # followup, six hours after # check if the followup is going to be after 10pm -- if so, move it to 10am the next day if f.hour >= 22: f += timedelta(days=1) f = f.replace(hour=10) # if 'schedule_date' is earlier than now, the scheduled event will be sent immediately try: # reminders (only schedule these if they're in the future) if a > datetime.now(): d1 = {'task': 'Appointment Reminder','user': self.user.identity,'args': self.args,'schedule_date': a,'session_id': session_id} taskscheduler.schedule(d1) if b > datetime.now(): d2 = {'task': 'Appointment Reminder','user': self.user.identity,'args': self.args,'schedule_date': b,'session_id': session_id} taskscheduler.schedule(d2) if c > datetime.now(): d3 = {'task': 'Appointment Reminder','user': self.user.identity,'args': self.args,'schedule_date': c,'session_id': session_id} taskscheduler.schedule(d3) # followup d4 = {'task': 'Appointment Followup','user': self.user.identity,'args': self.args,'schedule_date': f,'session_id': session_id} taskscheduler.schedule(d4) except Exception as e: print '%s' % (e)
def schedule_reminders(self, *args, **kwargs): ndatetime = kwargs["response"] session_id = kwargs["session_id"] print "in %s: user responsed with date: %s" % (self.__class__, kwargs["response"]) print "args: %s kwargs: %s" % (args, kwargs) print "self.args: %s" % (self.args) pdt = parsedatetime.Calendar() (res, retval) = pdt.parse(ndatetime) if retval == 0: raise ValueError("Unable to parse date time: %s" % (ndatetime)) # get the first 6 values from the stuct... the rest we do not care about t = datetime(*res[0:7]) # t = datetime.strptime(ndatetime, "%m/%d/%Y %H:%M:%S") s = timedelta(days=1) i = timedelta(microseconds=1) # support cens gui: appt_date used to display the appointment time only # Tuesday, 5:30pm, November 03, 2010 appttime = t.strftime("%A %I:%M%p, %B %d, %Y") # make sure we pass on the appointment date self.args["appt_date"] = appttime print "self.args: %s" % (self.args) testing = True if testing: # easier to track msgs s = timedelta(seconds=900) # 15 minutes a = t + s # first reminder 15 minutes after datetime reply b = t + 2 * s # second is 30 minutes after c = t + 3 * s # third is 45 after f = t + 4 * s # follow sent 1 hour after else: # actually, -3, -2, -1 days for reminders; +1 day for followup # NOTE: If we are one or two days before appointment, need to do the right thing here # so they do not get too many reminders a = t - 3 * s # two days before b = t - 2 * s # one night before c = t - s + i # morning of appointment f = t + s + i # followup, one day after... # if 'schedule_date' is earlier than now, the scheduled event will be sent immediately # sched 3 reminders. d1 = { "task": "Appointment Reminder", "user": self.user.identity, "args": self.args, "schedule_date": a, "session_id": session_id, } d2 = { "task": "Appointment Reminder", "user": self.user.identity, "args": self.args, "schedule_date": b, "session_id": session_id, } d3 = { "task": "Appointment Reminder", "user": self.user.identity, "args": self.args, "schedule_date": c, "session_id": session_id, } # sched followup d4 = { "task": "Appointment Followup", "user": self.user.identity, "args": self.args, "schedule_date": f, "session_id": session_id, } try: # reminders taskscheduler.schedule(d1) taskscheduler.schedule(d2) taskscheduler.schedule(d3) # followup taskscheduler.schedule(d4) except Exception as e: print "%s" % (e)