Skip to content

Instantly share code, notes, and snippets.

@nzoschke
Created January 6, 2010 19:56
Show Gist options
  • Save nzoschke/270584 to your computer and use it in GitHub Desktop.
Save nzoschke/270584 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2.4
import urllib
import httplib
from optparse import OptionParser, OptionGroup
GVHOST = 'clients4.google.com'
GVPATH = '/voice/embed/webButtonConnect'
BUTTONID = '7c175b61b7a363681b1db4d6522c5d4927614d0e'
def connect(caller_number):
"""Connect a phone call using a Google Voice Widget"""
data = urllib.urlencode({
'buttonId': BUTTONID,
'callerNumber': caller_number,
'showCallerNumber': 1,
'name': 'h'
})
headers = {
"Content-type": "application/x-www-form-urlencoded",
'User-Agent': "httplib"
}
conn = httplib.HTTPSConnection(GVHOST)
conn.request("POST", GVPATH, data, headers)
response = conn.getresponse()
data = response.read()
return ("ok=true" in data)
if __name__ == '__main__':
parser = OptionParser()
static_group = OptionGroup(parser, "Static Connect")
static_group.add_option("-c", "--caller-number",
help="The phone number originating the call.")
parser.add_option_group(static_group)
(options, args) = parser.parse_args()
if not options.caller_number:
parser.print_help()
sys.exit()
connect(options.caller_number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment