Examples

All of these can be found in the examples directory

Place calls

from googlevoice import Voice
from googlevoice.util import input

voice = Voice()
voice.login()

outgoingNumber = input('Number to call: ')
forwardingNumber = input('Number to call from [optional]: ') or None

voice.call(outgoingNumber, forwardingNumber)

if input('Calling now... cancel?[y/N] ').lower() == 'y':
    voice.cancel(outgoingNumber, forwardingNumber)

Download MP3s

from googlevoice import Voice

download_dir = '.'

voice = Voice()
voice.login()

for message in voice.voicemail().messages:
    message.download(download_dir)

Send SMS messages

from googlevoice import Voice
from googlevoice.util import input

voice = Voice()
voice.login()

phoneNumber = input('Number to send message to: ')
text = input('Message text: ')

voice.send_sms(phoneNumber, text)

Phones

from googlevoice import Voice,util

voice = Voice()
voice.login()

util.pprint(voice.phones)

Folders

from googlevoice import Voice,util,settings

voice = Voice()
voice.login()

for feed in settings.FEEDS:
    util.print_(feed.title())
    for message in getattr(voice, feed)().messages:
        util.print_('\t', message)

List voicemails

from googlevoice import Voice,util

voice = Voice()
voice.login()

for message in voice.voicemail().messages:
    util.print_(message)

Delete Messages

from googlevoice import Voice

voice = Voice()
voice.login()

for message in voice.sms().messages:
    if message.isRead:
        message.delete()

Parse received SMS

#
#SMS test via Google Voice
#
#John Nagle
#   nagle@animats.com
#
from googlevoice import Voice
import sys
import BeautifulSoup


def extractsms(htmlsms) :
    """
    extractsms  --  extract SMS messages from BeautifulSoup tree of Google Voice SMS HTML.

    Output is a list of dictionaries, one per message.
    """
    msgitems = []										# accum message items here
    #	Extract all conversations by searching for a DIV with an ID at top level.
    tree = BeautifulSoup.BeautifulSoup(htmlsms)			# parse HTML into tree
    conversations = tree.findAll("div",attrs={"id" : True},recursive=False)
    for conversation in conversations :
        #	For each conversation, extract each row, which is one SMS message.
        rows = conversation.findAll(attrs={"class" : "gc-message-sms-row"})
        for row in rows :								# for all rows
            #	For each row, which is one message, extract all the fields.
            msgitem = {"id" : conversation["id"]}		# tag this message with conversation ID
            spans = row.findAll("span",attrs={"class" : True}, recursive=False)
            for span in spans :							# for all spans in row
                cl = span["class"].replace('gc-message-sms-', '')
                msgitem[cl] = (" ".join(span.findAll(text=True))).strip()	# put text in dict
            msgitems.append(msgitem)					# add msg dictionary to list
    return msgitems
    
voice = Voice()
voice.login()

voice.sms()
for msg in extractsms(voice.sms.html):
    print str(msg)

List account settings

from googlevoice import Voice,util


voice = Voice()
voice.login()

util.pprint(voice.settings)

Table Of Contents

Previous topic

Command Line Script

Next topic

API Reference

This Page