ChrisProsser

send_sms.py

Oct 3rd, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. #!/usr/bin/python
  2. # using http://www.txtlocal.co.uk
  3. # note: you need to set up an account with txtlocal to use this script (you get 10 free messages to try it out)
  4.  
  5. import urllib, urllib2
  6.  
  7. def main(msg, numbers, user, sender_name):
  8.     """ numbers recieved as string, comma separated"""
  9.  
  10.     # https://control.txtlocal.co.uk/docs/
  11.     hash = 'your_hash_here ** (get from link in comment above) **'
  12.     test_flag = 0 # 0 for live 1 for test
  13.  
  14.     values = {'test'    : test_flag,
  15.               'uname'   : user,
  16.               'hash'    : hash,
  17.               'message' : msg,
  18.               'from'    : sender_name,
  19.               'selectednums' : numbers }
  20.  
  21.     url = 'http://www.txtlocal.com/sendsmspost.php'
  22.  
  23.     postdata = urllib.urlencode(values)
  24.     req = urllib2.Request(url, postdata)
  25.  
  26.     print 'Attempt to send SMS ...'
  27.  
  28.     try:
  29.         response = urllib2.urlopen(req)
  30.         response_url = response.geturl()
  31.         if response_url==url:
  32.             print 'SMS sent!'
  33.     except urllib2.URLError, e:
  34.         print 'Send failed!'
  35.         print e.reason
  36.  
  37. if __name__ == '__main__':
  38.     main()
Advertisement
Add Comment
Please, Sign In to add comment