I often come up with programming ideas as I’m trying to fall asleep and, more often than not, this forces me out of bed to start some silly work. About a year ago I had an idea: Would it be possible to create a script to text friends, family and/or strangers with some form of spam. For some reason I landed on the innocuous topic of feline facts and got right to work.
My first idea was to use the email system that has been in place for some time now to send the text messages. However, this requires me to know what network the phone is on and that’s a problem I wasn’t interested in dealing with. Then I remembered Google Voice… For the uninitiated, anyone with a Google account can now get an additional phone number, free of charge. You can configure Google Voice to forward your calls to whichever phones you chose while keeping your primary phone number concealed.
Python, being one of my favorite languages was the clear choice for this task. It turns out that Google has no public API for their Google Voice service. Thankfully, some pro programmers have created Google Voice libraries for a handful of languages, including Python. I used pygooglevoice which ended up being a pleasure to work with. The program prompts the user for their Google login (which is securely handed off to Google for verification) and then asks the user for the phone number they would like to send spam to. Also configurable is a time interval in which the texts will be sent. The cat facts are read from a file located in the same directory and, in theory, could be replaced with any text file in the same format.
Enough about the program – here it is:
inFile = open('catfacts.txt','r')
catFacts = 
for line in inFile:
line = line.strip('\n')
catFacts = readCatFacts()
user = raw_input('Please enter your Google username: ')
passwd = getpass.getpass('Please enter your return catFacts
Google password: ')
gvoice = pygvoicelib.GoogleVoice(user, passwd)
phoneList = gvoice.get_numbers()
except pygvoicelib.LoginError, e:
print 'Failed to login. Reason: %s' % (e.reason)
print 'Reasons Legend:'
print ' failed -> Invalid credentails'
print ' captcha -> Account is captcha locked'
print ' error -> Unknown/Other errors'
fromNum = -1;
for num in phoneList:
if num.isdigit() and phoneList[num]['verified']:
fromNum = num
print 'Login successful.'
if (fromNum == -1):
print 'Unable to find a validated phone to test a call with - goodbye!'
callNumber = input('Please enter the phone number to provide with cat facts: ')
callFrequencyMin = int(input("What's the minimum time between cat facts (minutes): "))
callFrequencyMax = int(input("What's the maximum time between cat facts (minutes): "))
e) + ' minutes'
for i in range(sleepTime*60, -1, -1):
print '\r' + str(i) + ' seconds remaining ',
sleepTime = random.randint(callFrequencyMin, callFrequencyMax)
catFactNum = random.randint(0,len(catFacts)-1)
successVar = repr(gvoice.send(callNumber, catFacts[catFactNum]))
print 'Attempting to send cat fact... Success -> ' + successVar
print 'Sleeping for ' + str(sleepTim
If you’re interested in the actual catfacts.txt file you can check it out here: catfacts.txt
Here are packaged executables for Windows and OSX – make sure you have a catfacts.txt file in the same directory as the executable or the app will crash!