Skip to content

Instantly share code, notes, and snippets.

@gduverger
Last active November 12, 2015 18:23
Show Gist options
  • Save gduverger/a6b6328b4fcfb08267b7 to your computer and use it in GitHub Desktop.
Save gduverger/a6b6328b4fcfb08267b7 to your computer and use it in GitHub Desktop.
How Fitmeal replies to text messages with nutrition facts (edited snippet)
def reply(request):
"""
Reply to a text message with nutrition facts (edited snippet)
"""
args = {}
if request.method == 'POST':
# Get the text message
text = request.POST.get('text')
# Find the food
features = app_process.extract_features(text)
# Find the nutrition facts
nutrients = app_process.compute_nutrients(features)
# Write the response
response = app_process.compose_response(nutrients)
if response:
args.update({'response': response})
else:
logger.error(text)
return render_to_response('reply.xml', args, context_instance=RequestContext(request), content_type='application/xml')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment