Skip to content

Commit

Permalink
parse more metadata from the database
Browse files Browse the repository at this point in the history
  • Loading branch information
Sail338 committed Jul 3, 2018
1 parent 90a4d9b commit 5bab776
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions garfield/lookup/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,46 @@
# Create your views here.
@twilio_view
def index(request):
"""
Endpoint to lookup contact information via Twilio
"""
print(request)
response = MessagingResponse()
response.message(lookup_contact(request))
parsed_data = lookup_contact(request))
if(parsed_data == {}):
response.message("Contact is not in the System")
else:
response.message("Number of Texts: "+ parsed_data['num_texts'])
response.message("Number of Calls: "+parsed_data['num_calls'])
response.message("Contact Count: "+ parsed_data['suspect_contact_count'])
response.message("Carrier: " + parsed_data['suspect_carrier'])
return response

def lookup_contact(request):
"""
Given a Phone Number in a twilio response body lookup the information
in our db and return meta data
:param request A query dict from twilio
"""
suspect_number = request.GET.get('From')
#init an empty dict for suspect info
suspect_information = {}
contact = Contact.objects.get(phone_number = suspect_number)

if contact != None:
return (contact.nextcaller_first_name)

num_texts = contact.sms_message_count
num_calls = contact.call_count
suspect_contact_count = contact.contact_count
#carrier information
suspect_carrier = contact.carrier
suspect_information['phone_number'] = suspect_number
suspect_information['num_texts'] = num_texts
suspect_information['num_calls'] = num_calls
suspect_information['suspect_contact_count'] = suspect_contact_count
suspect_information['suspect_carrier'] = suspect_carrier
return (suspect_information)
else:
return ("No contact")
return ({})


0 comments on commit 5bab776

Please sign in to comment.