コード例 #1
0
ファイル: main.py プロジェクト: gipsy86147/SMSSchedulingGAE
 def post(self):
     q_id = int(self.request.get('q_id'))
     q = QueueEntry.get_by_id(q_id)
     twilio_settings = TwilioSettings.all().get()
     schedule = SMSSchedule.all().get()
     tclient = TwilioRestClient(twilio_settings.account_sid, twilio_settings.auth_token)
     if q and q.status == 'P':
         employees = Employee.all()
         for employee in employees:
             entry = ReportingEntry.all().filter('reporting_date = ', q.report_date).filter('mobile_number =', employee.mobile_number).get()
             if not entry:
                 entry = ReportingEntry(name = employee.name, 
                            mobile_number = employee.mobile_number,
                            email = employee.email,
                            reporting_date = q.report_date,
                            reporting_location = "NOT REPORTED",
                            reporting_time = None,
                            employee = employee)
                 entry.put() 
             if schedule.status=='Active':                
                 tclient.sms.messages.create(to = employee.mobile_number, from_ = twilio_settings.twilio_number, body = schedule.message[:160])
                 smslog = SMSLog(message = schedule.message[:160],
                                 from_number = twilio_settings.twilio_number,
                                 to_number = employee.mobile_number,
                                 direction = 'outgoing-scheduled',
                                 employee_name = employee.name)
                 smslog.put()
         q.status = 'S'
         q.save()
コード例 #2
0
ファイル: main.py プロジェクト: gipsy86147/SMSSchedulingGAE
 def get(self):
     try:
         schedule = SMSSchedule.all().get()
         now = datetime.now()
         utc = UTC()
         est = Eastern_tzinfo()
         in_est = now.replace(tzinfo=utc).astimezone(est)
         est_date = in_est.date()
         if est_date.weekday() < 5 :
             eta = datetime.combine(est_date, time(int(schedule.scheduled_time)))
             eta_est = eta.replace(tzinfo=est)
             all_pending = QueueEntry.all().filter('status =', 'P')
             db.delete(all_pending)            
             q = QueueEntry(status="P",report_date=est_date,eta=eta_est)
             q.put()
             taskqueue.add(url='/sendSms', params={'q_id':q.key().id()}, eta = eta_est)
             result_dict = {'success':True,'message':'Queued'}
         else:
             result_dict = {'success':True,'message':'Not a working weekday'}
     except:
         result_dict = {'success':False,'message':'Cron job failed'}
         
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps(result_dict))