A sample script follows, based heavily on the gvoice script included in pygooglevoice:
import sys
from atexit import register
from optparse import OptionParser
from googlevoice import Voice,util
from googlevoice.util import LoginError,input,print_
parser = OptionParser(usage='''gvoice [-e-p ] commands
Where commands are
home
work
home2
out''')
parser.add_option("-e", "--email", dest="email", default=None,
help="Google Voice Account Email")
parser.add_option("-p", "--password", dest='passwd', default=None,
help='Your account password (prompted if blank)')
options, args = parser.parse_args()
def login(email=options.email, passwd=options.passwd):
global voice
try:
voice.login(options.email,options.passwd)
except LoginError:
if input('Login failed. Retry?[Y/n] ').lower() in ('', 'y'):
login(None, None)
else:
sys.exit(0)
try:
action,args = args[0],args[1:]
except IndexError:
print "you need to give a command"
sys.exit(2)
voice = Voice()
login()
register(voice.logout)
if action == "home":
voice.phones[0].disable() # work
voice.phones[1].enable() # mobile
voice.phones[2].enable() # home
voice.phones[3].disable() # home 2
elif action == "work":
voice.phones[0].enable()
voice.phones[1].disable()
voice.phones[2].enable()
voice.phones[3].disable()
elif action == "home2":
voice.phones[0].disable()
voice.phones[1].disable()
voice.phones[2].enable()
voice.phones[3].enable()
elif action == "out":
voice.phones[0].disable()
voice.phones[1].disable()
voice.phones[2].enable()
voice.phones[3].disable()
You give it three options - your email address, your password and the command (in this case home, home2, work and out):
gvforward.py -e ABCdefGHI9876543210@gmail.com -p password work
