Guest User

Free Mobile SMS notification service

a guest
Jun 16th, 2014
569
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """FREE MOBILE SMS NOTIFICATION
  5.  
  6. Send SMS notifications to your cell phone with the Free Mobile's new service.
  7. Enable it on your user account page and get your credentials !
  8.  
  9. Paste this code in a file, import it and invoke the send_sms function
  10.  
  11. >>> import freemobilesmsnotification as sms
  12. >>> sms.send_sms('12345678', 'TopSecretPassword', 'Hello World!')
  13. (True, 'Success')"""
  14.  
  15. from urllib import urlencode
  16. from urllib2 import urlopen, HTTPError
  17.  
  18. def send_sms(u, p, m):
  19.     """u : Free Mobile id
  20.    p : Service password
  21.    m : The message
  22.    
  23.    Returns a boolean and a status string."""
  24.  
  25.     query = urlencode({'user': u, 'pass': p, 'msg': m})
  26.     url = 'https://smsapi.free-mobile.fr/sendmsg?{}'.format(query)
  27.     errorcodes = {400: 'Missing Parameter',
  28.                   402: 'Spammer!',
  29.                   403: 'Access Denied',
  30.                   500: 'Server Down'}
  31.    
  32.     try:
  33.         urlopen(url)
  34.         return True, 'Success'
  35.    
  36.     except HTTPError as e:
  37.         return False, errorcodes[e.code]
  38.  
  39. def main():
  40.     u, p, m = '12345678', 'TopSecretPassword', 'Hello World !'
  41.     print send_sms(u, p, m)[1]
  42.     return 0
  43.  
  44. if __name__ == '__main__':
  45.     main()
RAW Paste Data