script to send sms via google voice

Posted on
Tue Oct 12, 2010 5:57 pm
baadpuppy offline
User avatar
Posts: 16
Joined: Oct 01, 2010
Location: Virginia

script to send sms via google voice

I was looking for a simple way to send sms messages from a google voice account to my cell. Phone Amego is close, but doesn't have hands-off scripting available yet. I emailed the author about it. In the mean time, I stumbled upon pygooglevoice. I much prefer python programming to applescripting. So, I quickly put together a google voice sms sending python script. I've put mine at /usr/local/bin/gvsms. Feel free to crib from it or use it as you see fit. You could call this from apple script with a do shell script. It takes two arguments, the first being the cell number (10 digits) and the second being the message.

Code: Select all
#!/usr/bin/env - python
from googlevoice import Voice
import os,sys,string

# note: this program presumes you have edited your .gvoice file to have your
#       username/password credentials.  Modify as needed.
# NOTE: no error handling to speak of.  Use at your own risk.  yada yada.
#       requires pygooglevoice
#       on macosx:
#           sudo easy_install simplejson
#           sudo easy_install -U pygooglevoice

def usage():
    print "usage: gvsms number message\n"
    sys.exit(123)

if len(sys.argv) < 2:
    usage()

mobileNumber = sys.argv[1]
smsMessage = ' '.join(sys.argv[2:])

# make sure the phone number isn't too bogus
for digit in mobileNumber:
    if digit not in string.digits:
        usage()
if len(mobileNumber) < 10: # 10 digits works with google voice
    usage()

# the google voice "magic"
voice = Voice()
voice.login()
voice.send_sms(mobileNumber, smsMessage)
voice.logout()
# comment the following if you don't want the extra verbosity
print "sent %s the message:  %s\n" % (mobileNumber, smsMessage)

# vim: syntax=python



Oh, and a word of warning. Linking this as the action for a motion detector without some kind of buffering is a bad idea. Google rate-limits the SMS messaging via google voice. Someone moving around in the garage looking for tools can easily trigger 25+ hits, and getting 25+ SMS messages for that 1 incident wouldn't be fun. Especially as they'd probably trickle in for quite a while thanks to the rate limiting.

I hope this is helpful,
jim

Posted on
Mon Oct 17, 2011 3:12 pm
ChrisB offline
User avatar
Posts: 41
Joined: Sep 12, 2011

Re: script to send sms via google voice

I know this is an old post but I'd like to get it working under Indigo 5. I spoke to Jim and he is no longer using it so I was hoping someone else is using it or can help me figure out why it is not working.

I installed both simplejson and pygooglevoice using the following commands:

sudo easy_install-2.5 simplejson
sudo easy_install-2.5 -U pygooglevoice

I updated the .gvoice file in my home folder to include my google voice username/password/number.

When I run the script above, I get the following message:

Code: Select all
  Script Error                    embedded script: EOF when reading a line
  Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 32, at top level
     File "/Library/Python/2.5/site-packages/googlevoice/voice.py", line 60, in login
       email = input('Email address: ')
EOFError: EOF when reading a line


I've even removed all the input statements and hard coded the values and I still get that message. What am I doing wrong?

Thanks,
Chris
Last edited by ChrisB on Tue Oct 18, 2011 9:51 am, edited 1 time in total.

Posted on
Tue Oct 18, 2011 7:33 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: script to send sms via google voice

Are you trying to execute the script from an Indigo action? Try just running the .py file by itself (not using Indigo). Does that work? Indigo does some internal modifications of the scripts it executes (embedded and external files) to automatically add the "indigo" module. Running the script outside of Indigo will help rule out that as the problem.

Image

Posted on
Tue Oct 18, 2011 10:05 am
ChrisB offline
User avatar
Posts: 41
Joined: Sep 12, 2011

Re: script to send sms via google voice

I went though and deleted all the modules and reinstalled using just these two commands:

sudo easy_install-2.5 simplejson
sudo easy_install-2.5 -U pygooglevoice

What I found out was that Google made a change and what is included in the pygooglevoice file does not work anymore. After it installed, I unzipped the pygooglevoice-0.5-py2.5.egg located in /Library/Python/2.5/site-packages. It will unzip two folders: EGG-INFO and googlevoice.

Inside the googlevoice folder, edit the settings.py and change the:

LOGIN = 'https://www.google.com/accounts/ServiceLoginAuth?service=grandcentral'

to

LOGIN = 'https://accounts.google.com/ServiceLogin?service=grandcentral'

Save the file, then re-zip both folders and rename the archive pygooglevoice-0.5-py2.5.egg. Replace the original .egg file with the new one.

I then created a file called gv.py with the following contents:

Code: Select all
#!/usr/bin/env - python
from googlevoice import Voice
import os,sys,string

mobileNumber = sys.argv[1]
smsMessage = ' '.join(sys.argv[2:])

# make sure the phone number isn't too bogus
for digit in mobileNumber:
    if digit not in string.digits:
        usage()
if len(mobileNumber) < 10: # 10 digits works with google voice
    usage()

# the google voice "magic"
voice = Voice()
voice.login()
voice.send_sms(mobileNumber, smsMessage)
voice.logout()


In order to test this out, I created a new action group with the following AppleScript:

do shell script "python2.5 /Users/Indigo/gv.py 5175551212 'This is neat!'"

It worked!

What's the best way to use it? I don't want Indigo to hang while it's waiting for the script to finish. Would creating a plugin be best or is there another way?

Thanks,
Chris

Posted on
Tue Oct 18, 2011 12:34 pm
ChrisB offline
User avatar
Posts: 41
Joined: Sep 12, 2011

Re: script to send sms via google voice

Never mind. I went ahead and created a simple plugin that has a single action. I wasn't sure if I could include the python code for pygooglevoice and simplesjon in the plugin (licensing issues?) so I left those out and relied on having them already installed.

It works well and I am now able to create actions with a cell number/text message and Indigo sends the SMS. With Google Voice, you can get a free phone number so all the text messages come for an actual 10 digit number - This allowed me to create a contact, on my phone, with the Indigo Server Google Number.

Chris

Posted on
Tue Oct 18, 2011 1:56 pm
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: script to send sms via google voice

Just turn the script into a method that takes the phone number and message as parameters, then save it in this directory:

~/Library/Python/2.5/site-packages/

So, if you named your file "gv.py", you would just run this script from Indigo:

Code: Select all
import gv
gv.yourHandlerName("5555551212", "This is neat!")


I'm not positive, but you may have to run the script in order to get it registered correctly with the Python interpreter (and get it compiled). Just do "python gv.py" in a terminal window which should compile it.

That directory's contents gets added to your Python path, so the import statement should import anything defined in the script. At some point, we want to add a directory to the plugin bundle that will be added to the Python path so you can provide methods and objects to other scripters (similar to the Attachments folder for AppleScripts). But that will have to wait until a later update... ;)

You'd need to check the license for the Google Voice code, but simplejson is included in the b9 build.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest