Пример #1
0
def data_post(request):
    try:
        lat				= request.REQUEST['lat']
        lon				= request.REQUEST['lon']
        message			= request.REQUEST['message']
    except KeyError:
        return JsonResponse({'error' : 'missing parameter'})

    timestamp = datetime.today()
    post = Post.objects.create(
        user		= request.user,
        datetime	= timestamp,
        lat			= lat,
        lon			= lon,
        message		= message,
    )

    result = twitter_post(request.user, message)
    return JsonResponse({'result' : result})
Пример #2
0
def data_imok(request, user_key):	
	try:
		lat				= request.REQUEST['lat']
		lon				= request.REQUEST['lon']
	except KeyError:
		return JsonResponse({'result' : False, 'error' : 'missing parameters'})

	try:
		phone = PhoneUser.objects.get(user_key=user_key)
	except ObjectDoesNotExist:
		return JsonResponse({'result' : False, 'error' : 'unknown user'})

	message			= "I'm Ok!"
	timestamp = datetime.today()
	post = Post.objects.create(
		user		= phone.user,
		datetime	= timestamp,
		lat			= lat,
		lon			= lon,
		message		= message,
	)

	result = twitter_post(phone.user, message)
	return JsonResponse({'result' : result})
Пример #3
0
def data_imok(request, user_key):	
	try:
		lat				= request.REQUEST['lat']
		lon				= request.REQUEST['lon']
	except KeyError:
		return JsonResponse({'result' : False, 'error' : 'missing parameters'})

	try:
		phone = PhoneUser.objects.get(user_key=user_key)
	except ObjectDoesNotExist:
		return JsonResponse({'result' : False, 'error' : 'unknown user'})

	message			= "I'm Ok!"
	timestamp = datetime.today()
	post = Post.objects.create(
		user		= phone.user,
		datetime	= timestamp,
		lat			= lat,
		lon			= lon,
		message		= message,
	)

	result = twitter_post(phone.user, message)
	return JsonResponse({'result' : result})
Пример #4
0
    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