Permalink
Browse files

Reworked phonecall notifications to display the caller's state and in…

…clude the callerid string
  • Loading branch information...
1 parent 8b05bd2 commit a15970d394c8aa7b41ab200ee97a2b91ee0573dc @lovett committed Apr 29, 2011
Showing with 894 additions and 5 deletions.
  1. +26 −4 appengine/models.py
  2. +801 −0 appengine/npa.csv
  3. +2 −1 appengine/phonecall.py
  4. +65 −0 appengine/states.csv
View
@@ -17,6 +17,7 @@
import os
import re
import logging
+import csv
class Profile(db.Model):
@@ -153,6 +154,7 @@ def formatPhonecall(self):
"""
caller_name = memcache.get(self.params["number"])
+ caller_name = None
formatted_number = None
if not caller_name:
@@ -177,7 +179,7 @@ def formatPhonecall(self):
candidate = re.sub("\D", "", phone.text)
if candidate.find(self.params["number"]) > -1:
caller_name = entry.title.text
- memcache.add(key=self.params["number"], value=caller_name)
+ memcache.add(key=self.params["number"], value=caller_name,time=18000) # cache for 5 hours
break
if caller_name:
break
@@ -197,12 +199,32 @@ def formatPhonecall(self):
formatted_number = self.params["number"]
area_code = ""
+ # Map the area code to the caller's state.
+ state_name = None
if area_code:
- self.message_for_web = "Unknown caller in area code %s" % area_code
+ npa_reader = csv.reader(open('npa.csv', 'rb'), delimiter=',')
+ for row in npa_reader:
+ if row[0] == area_code:
+ state_abbrev = row[1]
+ break
+
+ if state_abbrev:
+ state_reader = csv.reader(open('states.csv', 'rb'), delimiter=',')
+ for row in state_reader:
+ if row[1] == state_abbrev:
+ state_name = row[0].strip()
+ break
+
+ # Clean up the callerid name if present
+ if self.params["name"]:
+ caller_name = self.params["name"].title()
else:
- self.message_for_web = "Unknown caller"
+ caller_name = "an unknown caller"
- self.message_for_im = "Phonecall from %s" % formatted_number
+ self.message_for_im = "Phonecall from %s" % caller_name
+ if state_name:
+ self.message_for_im += " in %s" % state_name
+ self.message_for_web = self.message_for_im
self.message_for_log = self.message_for_im
self.source = self.params["number"]
Oops, something went wrong.

0 comments on commit a15970d

Please sign in to comment.