X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fbackends%2Fgvoice%2Fgvoice.py;h=f73600e1bc59f76f928ddb418378500fd5d8f350;hb=0ba0b153f9787ab64daead531eb0a71d1ecfbe14;hp=021a03c8ac64dd983ad593b479bdb025275b6da7;hpb=e4cfee57f895ec65b567ab82cb5e10e40497d66d;p=gc-dialer diff --git a/src/backends/gvoice/gvoice.py b/src/backends/gvoice/gvoice.py index 021a03c..f73600e 100755 --- a/src/backends/gvoice/gvoice.py +++ b/src/backends/gvoice/gvoice.py @@ -414,20 +414,21 @@ class GVoiceBackend(object): return json - def download(self, messageId, adir): + def recording_url(self, messageId): + url = self._downloadVoicemailURL+messageId + return url + + def download(self, messageId, targetPath): """ Download a voicemail or recorded call MP3 matching the given ``msg`` which can either be a ``Message`` instance, or a SHA1 identifier. - Saves files to ``adir`` (defaults to current directory). Message hashes can be found in ``self.voicemail().messages`` for example. @returns location of saved file. @blocks """ - page = self._get_page(self._downloadVoicemailURL, {"id": messageId}) - fn = os.path.join(adir, '%s.mp3' % messageId) - with open(fn, 'wb') as fo: + page = self._get_page(self.recording_url(messageId)) + with open(targetPath, 'wb') as fo: fo.write(page) - return fn def is_valid_syntax(self, number): """ @@ -478,14 +479,6 @@ class GVoiceBackend(object): ] return self._parse_recent(recentPages) - def get_contacts(self): - """ - @returns Iterable of (contact id, contact name) - @blocks - """ - page = self._get_page(self._JSON_CONTACTS_URL) - return self._process_contacts(page) - def get_csv_contacts(self): data = { "groupToExport": "mine", @@ -585,13 +578,6 @@ class GVoiceBackend(object): recentCallData["action"] = action yield recentCallData - def _process_contacts(self, page): - accountData = parse_json(page) - 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): @@ -1028,6 +1014,21 @@ def grab_debug_info(username, password): ) +def grab_voicemails(username, password): + cookieFile = os.path.join(".", "raw_cookies.txt") + try: + os.remove(cookieFile) + except OSError: + pass + + backend = GVoiceBackend(cookieFile) + backend.login(username, password) + voicemails = list(backend.get_voicemails()) + for voicemail in voicemails: + print voicemail.id + backend.download(voicemail.id, ".") + + def main(): import sys logging.basicConfig(level=logging.DEBUG) @@ -1037,6 +1038,7 @@ def main(): password = args[2] grab_debug_info(username, password) + grab_voicemails(username, password) if __name__ == "__main__":