Skip to content

Instantly share code, notes, and snippets.

@vitorio
Created September 20, 2016 18:06
Show Gist options
  • Save vitorio/77c45e17f08135d8235c7d50165789f7 to your computer and use it in GitHub Desktop.
Save vitorio/77c45e17f08135d8235c7d50165789f7 to your computer and use it in GitHub Desktop.
Manually search for matching local and toll-free Twilio numbers
import twilio
twilio_account_sid = ""
twilio_auth_token = ""
client = twilio.rest.TwilioRestClient(twilio_account_sid, twilio_auth_token)
## By default, Twilio will give you a selection of 30 numbers,
## so you want to search through a variety of patterns to find more
def trynumber(n):
numbers = client.phone_numbers.search(area_code="###", country="US", contains=n)
for a in numbers:
tf = client.phone_numbers.search(country="US", type="tollfree", contains='***'+a.phone_number[5:])
if tf:
for b in tf:
print a.phone_number, b.phone_number
else:
print a.phone_number, "no toll free match"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment