- 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