Thursday, December 26, 2013

Mass SMS with a Google Voice python script

Using the Google Voice interface. Or even your normal phone interface is tedious for sending mass text messages. I am sure there is an app or program that can make it easy to do. But I wanted to make my own.

Also, I don't know how to program (seriously, I don't) --- but I have done lots of simple scripting, so I figured this would be a good reason to force me to learn some things.

I am using Arch Linux. But I imagine ubuntu or windows will be pretty easy to do as well. If you're familiar with cloning source in a Linux environment, or installing Python things in a Windows environment, you'll have to adjust things.

Pre-reqs:

  • Have a Google Voice account
  • Have a very simple CSV file with names in the first column, and numbers in the second column
    • This means you'll need to have friends/family members :(
  • Have python installed (I have python 3 installed, but this script works better under 2, hence the "python2" commands issued below)
  • Have this python dealie:  https://bitbucket.org/fracai/pygooglevoice

 

 What do:


Unfortunately, the above python code linked can't handle 2-step authentication. I did a bunch of searching to find out the "fix" was to replace a single line in "voice.py"

So make a directory and clone the code:

hg clone https://bitbucket.org/fracai/pygooglevoice

Now you need to edit pygooglevoice/googlevoice/voice.py where it has:
Change it to read:

Now that you've fixed it, install the code. Go back to the pygooglevoice directory and run:
sudo python2 setup.py install

This will install all the goodies to /usr/lib/python2.7/site-packages/googlevoice/

Now you'll have a "binary" available for you to run (gvoice), but since I like to be fancy, instead I'll use the commands available in the code to make my own handy dandy script. I used these examples as my guide.

Then I made a CSV file in LibreOffice that just contains the name and the number. I imagine you can export CSV from your Google Contacts or Outlook Contacts if you'd like. Then just clean it up so the first column contains the name. And the second column contains the number.

Here's a dummy file:
https://dl.dropboxusercontent.com/u/22838635/code/example.csv

And here's the "code" that makes it all happen:


Here's a screen capture of the fun:


More things:


Just remember that if you use 2-step authentication, you'll need to enter your "SMS Pin" (which could be your authentication code generated from Google Authenticator).

Also, I'm not sure how Google Voice handles "spam" --- so I made sure to have the script pause for 8 seconds before it sends a message.

Shout-out to my buddy NouberNou, who helped me optimize the code (he's the uber-brains behind the Advanced Combat Radio Environment (ACRE) for ArmA). If you're curious to see what my first version looks like (and get a picture of how my code-dumb brain works) here's a pastebin link:
http://pastebin.com/8iA7vs0k

No comments:

Post a Comment