def getPfifRecord(post): imokUser = ImokUser.getProfileForUser(post.user) if post.positionText == '': if post.lat == 0.0: posText = '' else: posText = '%.6f,%.6f' % (post.lat, post.lon) else: posText = post.positionText if posText == '': posElt = ( '\n <pfif:last_known_location>%s</pfif:last_known_location>' % post.positionText) else: posElt = '' # FIX: remove TEST_PREFIX when we start pushing to real Person Finder TEST_PREFIX = 'iamok_' args = dict( imokHost='imokapp.appspot.com', userId=post.user.user_id(), entryDate=post.datetime.isoformat() + 'Z', firstName=TEST_PREFIX + imokUser.firstName, lastName=TEST_PREFIX + imokUser.lastName, userName='******' % (TEST_PREFIX, imokUser.firstName, TEST_PREFIX, imokUser.lastName), posElt=posElt, postId=post.unique_id, message=post.message, ) # We are intentionally leaving out some PFIF fields that we # have info for, due to privacy concerns. Any information we send # to Person Finder is totally public. return '''<?xml version="1.0" encoding="utf-8"?> <pfif:pfif xmlns:pfif="http://zesty.ca/pfif/1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://zesty.ca/pfif/1.2 http://zesty.ca/pfif/1.2/pfif-1.2.xsd"> <pfif:person> <pfif:person_record_id>%(imokHost)s/%(userId)s</pfif:person_record_id> <pfif:entry_date>%(entryDate)s</pfif:entry_date> <pfif:author_name>%(userName)s</pfif:author_name> <pfif:source_name>%(imokHost)s</pfif:source_name> <pfif:source_date>%(entryDate)s</pfif:source_date> <pfif:source_url>http://%(imokHost)s/person/%(userId)s</pfif:source_url> <pfif:first_name>%(firstName)s</pfif:first_name> <pfif:last_name>%(lastName)s</pfif:last_name> <pfif:note> <pfif:note_record_id>%(imokHost)s/post/%(postId)s</pfif:note_record_id> <pfif:person_record_id>%(imokHost)s/%(userId)s</pfif:person_record_id> <pfif:entry_date>%(entryDate)s</pfif:entry_date> <pfif:author_name>%(userName)s</pfif:author_name> <pfif:source_date>%(entryDate)s</pfif:source_date> <pfif:status>believed_alive</pfif:status> <pfif:found>true</pfif:found>%(posElt)s <pfif:text> Full text of status SMS: %(message)s </pfif:text> </pfif:note> </pfif:person> </pfif:pfif> ''' % args
def getPfifRecord(post): imokUser = ImokUser.getProfileForUser(post.user) if post.positionText == "": if post.lat == 0.0: posText = "" else: posText = "%.6f,%.6f" % (post.lat, post.lon) else: posText = post.positionText if posText == "": posElt = "\n <pfif:last_known_location>%s</pfif:last_known_location>" % post.positionText else: posElt = "" # FIX: remove TEST_PREFIX when we start pushing to real Person Finder TEST_PREFIX = "iamok_" args = dict( imokHost="imokapp.appspot.com", userId=post.user.user_id(), entryDate=post.datetime.isoformat() + "Z", firstName=TEST_PREFIX + imokUser.firstName, lastName=TEST_PREFIX + imokUser.lastName, userName="******" % (TEST_PREFIX, imokUser.firstName, TEST_PREFIX, imokUser.lastName), posElt=posElt, postId=post.unique_id, message=post.message, ) # We are intentionally leaving out some PFIF fields that we # have info for, due to privacy concerns. Any information we send # to Person Finder is totally public. return ( """<?xml version="1.0" encoding="utf-8"?> <pfif:pfif xmlns:pfif="http://zesty.ca/pfif/1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://zesty.ca/pfif/1.2 http://zesty.ca/pfif/1.2/pfif-1.2.xsd"> <pfif:person> <pfif:person_record_id>%(imokHost)s/%(userId)s</pfif:person_record_id> <pfif:entry_date>%(entryDate)s</pfif:entry_date> <pfif:author_name>%(userName)s</pfif:author_name> <pfif:source_name>%(imokHost)s</pfif:source_name> <pfif:source_date>%(entryDate)s</pfif:source_date> <pfif:source_url>http://%(imokHost)s/person/%(userId)s</pfif:source_url> <pfif:first_name>%(firstName)s</pfif:first_name> <pfif:last_name>%(lastName)s</pfif:last_name> <pfif:note> <pfif:note_record_id>%(imokHost)s/post/%(postId)s</pfif:note_record_id> <pfif:person_record_id>%(imokHost)s/%(userId)s</pfif:person_record_id> <pfif:entry_date>%(entryDate)s</pfif:entry_date> <pfif:author_name>%(userName)s</pfif:author_name> <pfif:source_date>%(entryDate)s</pfif:source_date> <pfif:status>believed_alive</pfif:status> <pfif:found>true</pfif:found>%(posElt)s <pfif:text> Full text of status SMS: %(message)s </pfif:text> </pfif:note> </pfif:person> </pfif:pfif> """ % args )
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