#!/usr/bin/env python # Copyright (C) 2008 Travis Spencer # All rights reserved # Licensed under the GNU GPL v. 2 # http://www.gnu.org/licenses/gpl-2.0.html import twiliorest import sys import re # Twilio REST API version API_VERSION = '2008-08-01' # Twilio AccountSid and AuthToken ACCOUNT_SID = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' ACCOUNT_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY' # Outgoing Caller ID previously validated with Twilio CALLER_ID = 'YYY-YYY-YYYY'; line = sys.stdin.readline() phonePattern = re.compile("callme (.*)") phoneNumber = None # Find the phone number while line: groups = phonePattern.search(line) if groups != None and len(groups.groups()) == 1: phoneNumber = groups.groups()[0] break line = sys.stdin.readline() # Bail if the phone number and callme command wasn't found if phoneNumber == None: sys.exit(1) log = open('/home/linux/tspencer/tweetbot.log', "a") print >>log, phoneNumber # Create a Twilio REST account object using your Twilio account ID and token account = twiliorest.Account(ACCOUNT_SID, ACCOUNT_TOKEN) # Initiate a new outbound call useing an HTTP POST d = { 'Caller' : CALLER_ID, 'Called' : phoneNumber, 'Url' : 'http://web.cecs.pdx.edu/~tspencer/twiliotest.xml', } print >>log, account.request('/%s/Accounts/%s/Calls' % \ (API_VERSION, ACCOUNT_SID), 'POST', d)