def post(self): self.response.headers['Content-Type'] = 'text/json' phone = Phone.normalize_number(self.request.get('phone')) message = self.request.get('message') if not (message and phone): result = { 'result': 'error', 'message': 'missing phone and/or message' } self.response.out.write(json.dumps(result)) return sms_message = SmsMessage(phone_number=phone, message=message, direction='incoming', status='unclaimed') objects = [ sms_message ] phone_entity = Phone.all().filter('number =', phone).get() if phone_entity: post = Post.fromText(message) post.unique_id = Post.gen_unique_key() post.user = phone_entity.user objects.append(post) sms_message.status = 'queued' db.put(objects) #self.response.out.write(message) self.response.out.write(json.dumps({'result': 'ok'}))
def post(self): self.response.headers['Content-Type'] = 'text/json' phone = Phone.normalize_number(self.request.get('phone')) message = self.request.get('message') if not (message and phone): result = { 'result': 'error', 'message': 'missing phone and/or message' } self.response.out.write(json.dumps(result)) return sms_message = SmsMessage(phone_number=phone, message=message, direction='incoming', status='unclaimed') objects = [ sms_message ] phone_entity = Phone.all().filter('number =', phone).get() if not phone_entity: db.put(objects) self.response.out.write(json.dumps({'result': 'ok'})) return post = Post.fromText(message) post.unique_id = Post.gen_unique_key() post.user = phone_entity.user objects.append(post) sms_message.status = 'queued' db.put(objects) imok_user = ImokUser.all().filter('account =', phone_entity.user).get() email_query = RegisteredEmail.all().filter('userName ='******'emailAddress') for email in email_query: template_data = { 'message': post.message, 'link': post.permalink(self.request.host_url), 'unsubscribe_link': email.permalink(self.request.host_url), 'user': imok_user } body = template.render(s.template_path('email.txt'), template_data) mail.send_mail(sender='*****@*****.**', to=email.emailAddress, subject="I'm OK", body=body) sms_message.status = 'processed' response_sms = SmsMessage(phone_number=phone, message="I'm OK: Message received. %d contact(s) notified." % email_query.count(), direction="outgoing", status="queued") db.put([ response_sms, sms_message ]) #self.response.out.write(message) self.response.out.write(json.dumps({'result': 'ok'}))
def get(self): phone = self.request.get('phone') message = self.request.get('message') self.response.headers['Content-Type'] = 'text/plain' if not message: self.response.out.write('missing message') return post = Post() post.message = message post.put() self.response.out.write(message)
def post(self): subject = self.request.get('subject') content = self.request.get('content') if subject and content: a = Post(title = subject, article = content) a.put() id = a.key().id() sleep(0.1) memcache.set(str(id), a) st['p'] = time.time() self.redirect('/blog/%d' % id, id) else: error = 'We need both title and article!' self.write_art(subject, content, error)
def get(self): posts = Post.all() #.gql() template_data = { 'posts' : posts, } template_path = s.template_path('incoming.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(template.render(template_path, template_data))
def get_key(self, label): data = memcache.get(label) if data: return data, None elif label == 'catalog': data = db.GqlQuery('select * from Post order by created desc') logging.info('*** Query Query Query ***') memcache.set(label, data) return data, time.time() elif label == 'blog': data = db.GqlQuery('select * from Post order by created desc limit 10') logging.info('*** Query Query Query ***') memcache.set(label, data) return data, time.time() else: data = Post.get_by_id(int(label)) logging.info('*** Query Query Query ***') memcache.set(str(label), data) return data, time.time()
def post(self): self.response.headers['Content-Type'] = 'text/json' phone = Phone.normalize_number(self.request.get('phone')) message = self.request.get('message') if not (message and phone): result = { 'result': 'error', 'message': 'missing phone and/or message' } self.response.out.write(json.dumps(result)) return sms_message = SmsMessage(phone_number=phone, message=message, direction='incoming', status='unclaimed') objects = [ sms_message ] phone_entity = Phone.all().filter('number =', phone).get() if not phone_entity: db.put(objects) self.response.out.write(json.dumps({'result': 'ok'})) return post = Post.fromText(message) post.unique_id = Post.gen_unique_key() post.user = phone_entity.user objects.append(post) sms_message.status = 'queued' db.put(objects) imok_user = ImokUser.all().filter('account =', phone_entity.user).get() email_query = RegisteredEmail.all().filter('userName ='******'emailAddress') for email in email_query: template_data = { 'message': post.message, 'link': post.permalink(self.request.host_url), 'unsubscribe_link': email.permalink(self.request.host_url), 'user': imok_user } body = template.render(s.template_path('email.txt'), template_data) mail.send_mail(sender=s.MAILER_EMAIL, to=email.emailAddress, subject="IMOk status", body=body) sms_message.status = 'processed' # Response_sms = SmsMessage(phone_number=phone, # message="IMOk: Message received, %d contact(s) notified." % email_query.count(), # direction="outgoing", # status="queued") sendSms(phone=phone_entity, message="IMOk: Message received, %d contact(s) notified." % email_query.count()) # db.put([ response_sms, sms_message ]) db.put([sms_message]) #self.response.out.write(message) self.response.out.write(json.dumps({'result': 'ok'}))
def savePostAndPush(self, text, phoneNumber, user, smsMessage=None, bogusTimestamp=None): post = Post.fromText(text) if bogusTimestamp != None: post.datetime = bogusTimestamp post.unique_id = Post.gen_unique_key() post.user = user objects = [post] if smsMessage != None: smsMessage.status = 'queued' objects.append(smsMessage) db.put(objects) ###################################################################### # send email # FIX: this block of code does not belong in sms_twilio imok_user = ImokUser.getProfileForUser(user) email_query = RegisteredEmail.all().filter('userName ='******'emailAddress') debugOutput = [] for email in email_query: template_data = { 'message': post.message, 'link': post.permalink(self.request.host_url), 'unsubscribe_link': email.permalink(self.request.host_url), 'user': imok_user } body = template.render(s.template_path('email.txt'), template_data) debugOutput.append(body) mail.send_mail(sender=s.MAILER_EMAIL, to=email.emailAddress, subject="IMOk status", body=body) twitter_post(imok_user, post.message) ###################################################################### # post to person finder if 0: debugText = personFinder.postToPersonFinder(post) debugOutput.append(debugText) ###################################################################### # send confirmation SMS if smsMessage != None: smsMessage.status = 'processed' smsMessage.put() response_sms = SmsMessage( phone_number=phoneNumber, message="I'm OK: Message received, %d contact(s) notified." % email_query.count(), direction="outgoing", status="queued") #response_sms.put() sendSms(response_sms) #self.response.out.write(message) #self.response.out.write(json.dumps({'result': 'ok'})) return debugOutput