<commit_before>#!/usr/bin/env python 

"""
Author          :   <NAME><http://www.linuxian.com>
Purpose         :   Send free sms using www.indyarocks.com
Date            :   Thu Jan  2 21:36:00 IST 2014
Dependencies    :   1. Your number MUST be register with  indyarocks
                    2. Python 2.7.3 Modules can be install using :
                         - pip install requests
                         - pip install docopt
Reports Bugs	:   https://github.com/rahulinux/sendsms/issues
"""
from __future__ import print_function
from docopt import docopt
import requests

usage = """
Usage:
        sendsms.py -u <username> -p <password> -to <send_to> -m	<msg>
        sendsms.py (-h | --help)
        sendsms.py --version

Note: if your password or message have special character then use double quotes 
"""

class	Sms(object):
		"""for login and send sms and logout """
		def __init__(self,username,password,send_to):
			self.username = username
			self.password = password
			self.send_to = send_to
			self.session = requests.session()
			
		def login(self):
			url = 'http://www.indyarocks.com/login'
			login_form = {
				'LoginForm[username]' : self.username,
				'LoginForm[password]' : self.password,
				'yt0':  'Login',
				}
			self.login_status = self.session.post(url, data=login_form)
			return self.login_status.text
			
		def send(self,sms_content):
			compose_sms_link = 'http://www.indyarocks.com/send-free-sms'
			send_sms_form = {
				'freeSmschkmemberVal' : 'NM',
				'FreeSms[mobile]' : self.send_to,
				'FreeSms[post_message]' : sms_content,
				'yt0' : 'SEND',
			}
			self.sent_status = self.session.post(compose_sms_link, data=send_sms_form)
                        return self.sent_status.text

		def logout(self):
			logout_link = 'http://www.indyarocks.com/logout'
			self.session.post(logout_link)
			
			
			
	
if __name__ == '__main__':
	args = docopt(usage,version='sendsms.py version 0.1 by <NAME><http://linuxian.com>')
	username, password, send_to = args['<username>'], args['<password>'], args['<send_to>']
	text = args['<msg>']
	sms = Sms(username,password,send_to)
	login_status = sms.login()
	if 'Logout' in login_status:
		print("Successfully Login with UserID: {0}".format(username))
	else:	
		print("Incorrect Username/Passoword")
		raise SystemExit(1)
        sms_status = sms.send(text)
        if '200' in sms_status:
                print("SMS Successfully Sent to [ {0} ]".format(send_to))
	sms.logout()<commit_msg>updated and tested code<commit_after>#!/usr/bin/env python 

"""
Author          :   <NAME><http://www.linuxian.com>
Purpose         :   Send free sms using www.indyarocks.com
Date            :   Thu Jan  2 21:36:00 IST 2014
Dependencies    :   1. Your number MUST be register with  indyarocks
                    2. Python 2.7.3 Modules can be install using :
                         - pip install requests
                         - pip install docopt
Reports Bugs	:   https://github.com/rahulinux/sendsms/issues
"""
from __future__ import print_function
from docopt import docopt
import requests

usage = """
Usage:
        sendsms.py -u <username> -p <password> -to <send_to> -m	<msg>
        sendsms.py (-h | --help)
        sendsms.py --version

Note: if your password or message have special character then use double quotes 
"""


class	Sms(object):
		"""for login and send sms and logout """
		def __init__(self,username,password,send_to):
			self.username = username
			self.password = password
			self.send_to = send_to
			self.session = requests.session()
			self.session.headers.pop('User-Agent')
			self.session.headers['User-Agent'] = 'Mozilla/5.0 Firefox/0.8'
			
		def login(self):
			url = 'http://www.indyarocks.com/login'
			login_form = {
				'LoginForm[username]' : self.username,
				'LoginForm[password]' : <PASSWORD>,
				'yt0':  'Login',
				}
			self.login_status = self.session.post(url, data=login_form)
			return self.login_status.text
			
		def send(self,sms_content):
			compose_sms_link = 'http://www.indyarocks.com/send-free-sms'
			send_sms_form = {
				'freeSmschkmemberVal' : 'NM',
				'FreeSms[mobile]' : self.send_to,
				'FreeSms[post_message]' : sms_content,
				'yt0' : 'SEND',
			}
			self.sent_status = self.session.post(compose_sms_link, data=send_sms_form)
                        return self.sent_status

		def logout(self):
			logout_link = 'http://www.indyarocks.com/logout'
			self.session.post(logout_link)
			
			
			
	
if __name__ == '__main__':
	args = docopt(usage,version='sendsms.py version 0.1 by <NAME><http://linuxian.com>')
	username, password, send_to = args['<username>'], args['<password>'], args['<send_to>']
	text = args['<msg>']
	#raise SystemExit(1)
	sms = Sms(username,password,send_to)
	login_status = sms.login()
	if 'Logout' in login_status:
		print("Successfully Login with UserID: {0}".format(username))
	else:	
		print("Incorrect Username/Passoword")
		raise SystemExit(1)
        sms_status = sms.send(text)
	print(sms_status.request.headers)
	msg = 'Your Message has been sent successfully'
        if msg in sms_status.text:
                print("{0} [ {1} ]".format(msg,send_to))
	else:
		print('Error! Too many SMS-es sent')
		print('Per Day only 100 SMS-es allowed')
	sms.logout()
{'fraction_non_alphanumeric': 0.13144822315628582, 'fraction_numerical': 0.01108139090561712, 'mean_word_length': 2.9479638009049776, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 2, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7405090', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1785, 'n_words': 401}