Permalink
Browse files

Adding voicemail support and updating GVNotify for new GV HTML

  • Loading branch information...
1 parent 62b85ed commit ea91ea526c74d9c91769f38da080ffd9a3fba791 Mike committed Aug 13, 2009
Showing with 44 additions and 6 deletions.
  1. +42 −6 googlevoicenotify.py
  2. +2 −0 prowlgooglevoice.py
View
@@ -28,7 +28,7 @@ def __init__(self, username, password, listeners=None, picklefile='/tmp/pickled-
# if a previous session quit but saved state, load it to
# avoid double notifications
try:
- cached_fl = open('pickled-updates', 'r')
+ cached_fl = open(picklefile, 'r')
self.convo_threads = pickle.load(cached_fl)
cached_fl.close()
except Exception, e:
@@ -73,7 +73,7 @@ def parse_result(self, result):
sp = BeautifulSoup(cleaned)
# parse SMS threads
- sms = sp.findAll('div', attrs={'class':'gc-message gc-message-sms'})
+ sms = sp.findAll('div', attrs={'class':'goog-flat-button gc-message gc-message-sms'})
for thread in sms:
id = thread['id']
# find all message rows
@@ -93,12 +93,48 @@ def parse_result(self, result):
for listener in self.listeners:
listener.on_notification('SMS', from_name, message_txt)
# debug: print message_txt
- out_fl = open(self.picklefile, 'w')
- pickle.dump(self.convo_threads, out_fl)
-
+
+ def get_voicemails(self):
+ # if we haven't acquired cookies yet
+ if len(self.cookies) == 0:
+ # first do the login POST
+ login = self.do_req('https://www.google.com/accounts/ServiceLoginBoxAuth?Email=%s&Passwd=%s&service=grandcentral' % (self.username, self.password)).read()
+ # second step is to pass the cookie check
+ cookie_check = self.do_req('https://www.google.com/accounts/CheckCookie?chtml=LoginDoneHtml').read()
+ html = self.do_req('https://www.google.com/voice/inbox/recent/voicemail/').read()
+ sp = BeautifulStoneSoup(html)
+ return str(sp.response.html.contents[0])
+ def parse_voicemails(self, result):
+ cleaned = result.replace('</div></div></div></div></div>', '</div></div></div></div>')
+ sp = BeautifulSoup(cleaned)
+ voicemails = sp.findAll('div', attrs={'class':'goog-flat-button gc-message gc-message-unread'})
+ for voicemail in voicemails:
+ id = voicemail['id']
+ # find all voicemail rows
+ rows = voicemail.findAll('table', attrs={'class':'gc-message-tbl'})
+ for message in rows:
+ from_name = message.findAll('a', attrs={'class':'gc-under gc-message-name-link'})[0].string.strip()
+ span_array = message.findAll('div', attrs={'class':'gc-message-message-display'})[0].findAll('span', attrs={'class':'gc-word-high'})
+ voicemail_transcript_array = []
+ for word in span_array:
+ voicemail_transcript_array.append(word.string.strip())
+ voicemail_transcript = ' '.join(voicemail_transcript_array)
+ identifier = from_name + ' ' + voicemail_transcript
+ if identifier not in self.convo_threads[id]:
+ self.convo_threads[id].add(identifier)
+ if from_name != 'Me':
+ if self.listeners and len(self.listeners) > 0:
+ for listener in self.listeners:
+ listener.on_notification('Voicemail', from_name, voicemail_transcript)
+
def check(self):
feed = self.get_inbox()
feed = feed.replace("<![CDATA[", "")
feed = feed.replace("]]>", "")
self.parse_result(feed)
-
+ vmfeed = self.get_voicemails()
+ vmfeed = vmfeed.replace("<![CDATA[", "")
+ vmfeed = vmfeed.replace("]]>", "")
+ self.parse_voicemails(vmfeed)
+ out_fl = open(self.picklefile, 'w')
+ pickle.dump(self.convo_threads, out_fl)
View
@@ -60,6 +60,8 @@ def readparams(cfile):
picklefile = environ['HOME']+'/.gvcache')
del passwd
while True:
+ # uncomment below for debugging
+ # print 'sleeping...'
gv.check()
sleep(sleep_time)

0 comments on commit ea91ea5

Please sign in to comment.