X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fgvoice%2Fbackend.py;h=0661d0c0af2f164d8e46466eeb5124316f9fd24e;hb=4329f6e4cdab994dbe81ea03e1c36341be37d253;hp=9996e74ba345688297faabb42351f7376b89a45e;hpb=a3d4b5a03a1c10621db4b193d50e1c64410de0d7;p=theonering diff --git a/src/gvoice/backend.py b/src/gvoice/backend.py index 9996e74..0661d0c 100755 --- a/src/gvoice/backend.py +++ b/src/gvoice/backend.py @@ -304,6 +304,11 @@ class GVoiceBackend(object): self._lastAuthed = time.time() return True + def shutdown(self): + self._browser.save_cookies() + self._token = None + self._lastAuthed = 0.0 + def logout(self): self._browser.clear_cookies() self._browser.save_cookies() @@ -473,18 +478,15 @@ class GVoiceBackend(object): @returns Iterable of (personsName, phoneNumber, exact date, relative date, action) @blocks """ - for action, url in ( - ("Received", self._XML_RECEIVED_URL), - ("Missed", self._XML_MISSED_URL), - ("Placed", self._XML_PLACED_URL), - ): - flatXml = self._get_page(url) - - allRecentHtml = self._grab_html(flatXml) - allRecentData = self._parse_history(allRecentHtml) - for recentCallData in allRecentData: - recentCallData["action"] = action - yield recentCallData + recentPages = [ + (action, self._get_page(url)) + for action, url in ( + ("Received", self._XML_RECEIVED_URL), + ("Missed", self._XML_MISSED_URL), + ("Placed", self._XML_PLACED_URL), + ) + ] + return self._parse_recent(recentPages) def get_contacts(self): """ @@ -492,14 +494,7 @@ class GVoiceBackend(object): @blocks """ page = self._get_page(self._XML_CONTACTS_URL) - contactsBody = self._contactsBodyRe.search(page) - if contactsBody is None: - raise RuntimeError("Could not extract contact information") - accountData = _fake_parse_json(contactsBody.group(1)) - for contactId, contactDetails in accountData["contacts"].iteritems(): - # A zero contact id is the catch all for unknown contacts - if contactId != "0": - yield contactId, contactDetails + return self._process_contacts(page) def get_voicemails(self): """ @@ -584,6 +579,24 @@ class GVoiceBackend(object): raise RuntimeError("Not Authenticated") return number + def _parse_recent(self, recentPages): + for action, flatXml in recentPages: + allRecentHtml = self._grab_html(flatXml) + allRecentData = self._parse_history(allRecentHtml) + for recentCallData in allRecentData: + recentCallData["action"] = action + yield recentCallData + + def _process_contacts(self, page): + contactsBody = self._contactsBodyRe.search(page) + if contactsBody is None: + raise RuntimeError("Could not extract contact information") + accountData = _fake_parse_json(contactsBody.group(1)) + for contactId, contactDetails in accountData["contacts"].iteritems(): + # A zero contact id is the catch all for unknown contacts + if contactId != "0": + yield contactId, contactDetails + def _parse_history(self, historyHtml): splitVoicemail = self._seperateVoicemailsRegex.split(historyHtml) for messageId, messageHtml in itergroup(splitVoicemail[1:], 2):