Coder Social home page Coder Social logo

way2sms's Introduction

Way2Sms

Send upto 2 free SMS instantly.

Way2Sms provides free SMS service upto 2 messages daily with message length upto 139.

Install

pip3 install sch-way2sms==0.0.1

Usage

import way2sms
# your login credentials
sms = way2sms.Sms("9XXXXXXXXX", "PASSWORD")
sms.send("9XXXXXXXXX", "Hi, this package is awesome! Lets me send free messages")
sms.logout()

Future Message added by AbdHan

way2sms's People

Contributors

abdhan avatar shubhamc183 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

way2sms's Issues

Can't login, once check credential..! please guide me.credentials are correct.

import requests
from bs4 import BeautifulSoup

#".*//"
class sms:
def init(self,username,password):

	'''
	Takes username and password as parameters for constructors
	and try to log in
	'''

	self.url='http://www.way2sms.com/Login1.action?'

	self.cred={'username': username, 'password': password}

	self.s=requests.Session()			# Session because we want to maintain the cookies

	'''
	changing s.headers['User-Agent'] to spoof that python is requesting
	'''
	print("username"+username)

	self.s.headers['User-Agent'] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36"
	self.s.headers['Referer'] = "http://www.way2sms.com/content/index.html"    #http://www.way2sms.com/content/index.html
	self.s.headers['Host'] = "www.way2sms.com"
	print("host")
	print(self.url)

	self.q=self.s.post(self.url,data=self.cred)
	print("details")

	self.loggedIn=False				# a variable of knowing whether logged in or not
	print("self.loggedIn"+self.loggedIn)

	if "http://www.way2sms.com/main.action" in self.q.url:			# http status 200 == OKhttp://www.way2sms.com/main.action;jsessionid=8AC39E41522005C2882BFA783D5B3389.w803?Token=8AC39E41522005C2882BFA783D5B3389.w803&section=s

		print("Successfully logged in..!")

		self.loggedIn=True

	else:

		print("Can't login, once check credential..!")

		self.loggedIn=False

	self.jsid=self.s.cookies.get_dict()['JSESSIONID'][4:]	    # JSID is the main KEY as JSID are produced every time a session satrts

def msgSentToday(self):

	'''
	Returns number of SMS sent today as there is a limit of 100 messages everyday..!
	'''

	if self.loggedIn == False:
		print("Can't perform since NOT logged in..!")
		return -1

	self.msg_left_url='http://www.way2sms.com/sentSMS?Token='+self.jsid

	self.q=self.s.get(self.msg_left_url)

	self.soup=BeautifulSoup(self.q.text,'html.parser')		#we want the number of messages sent which is present in the

	self.t=self.soup.find("div",{"class":"hed"}).h2.text		# div element with class "hed" -> h2

	self.sent=0

	for self.i in self.t:

		if self.i.isdecimal():

			self.sent=10*self.sent+int(self.i)

	return self.sent

def send(self,mobile_no,msg):

	'''
	Sends the message to the given mobile number
	'''

	if self.loggedIn == False:
		print("Can't perform since NOT logged in..!")
		return False

	if len(msg)>139 or len(mobile_no)!=10 or not mobile_no.isdecimal():	#checks whether the given message is of length more than 139

		return False							#or the mobile_no is valid

	self.payload={'ssaction':'ss',
			'Token':self.jsid,					#inorder to visualize how I came to these payload,
		        'mobile':mobile_no,					#must see the NETWORK section in Inspect Element
   				 'message':msg,						#while messagin someone from your browser
		        'msgLen':'129'
   			     }

	self.msg_url='http://www.way2sms.com/smstoss.action'

	self.q=self.s.post(self.msg_url,data=self.payload)

	if self.q.status_code==200:

		return True

	else:
		return False

def sendLater(self, mobile_no, msg, date, time):				#Function for future SMS feature.
										#date must be in dd/mm/yyyy format
										#time must be in 24hr format. For ex: 18:05

	if self.loggedIn == False:
		print("Can't perform since NOT logged in..!")
		return False
	
	if len(msg)>139 or len(mobile_no)!=10 or not mobile_no.isdecimal():
		return False

	dateparts = date.split('/')			#These steps to check for valid date and time and formatting
	timeparts = time.split(':')
	if int(dateparts[0])<1 or int(dateparts[0])>32 or int(dateparts[1])>12 or int(dateparts[1])<1 or int(dateparts[2])<2017 or int(timeparts[0])<0 or int(timeparts[0])>23 or int(timeparts[1])>59 or int(timeparts[1])<0:
		return False
	date = dateparts[0].zfill(2) + "/" + dateparts[1].zfill(2) + "/" + dateparts[2]
	time = timeparts[0].zfill(2) + ":" + timeparts[1].zfill(2)

	self.payload={'Token':self.jsid,
			'mobile':mobile_no,
			'sdate':date,
			'stime':time,
			'message':msg,
			'msgLen':'129'
			}

	self.msg_url='http://www.way2sms.com/schedulesms.action'
	self.q=self.s.post(self.msg_url, data=self.payload)

	if self.q.status_code==200:
		return True
	else:
		return False

def logout(self):

	self.s.get('http://www.way2sms.com/entry?ec=0080&id=dwks')

	self.s.close()								# close the Session

	self.loggedIn=False

Error*****************

import way2sms.py
q=way2sms.sms('9458545666','KSD8')
Can't login, once check credential..!
Traceback (most recent call last):
File "", line 1, in
File "D:\Program Files\Python\Python36\way2sms.py", line 45, in init
self.jsid=self.s.cookies.get_dict()['JSESSIONID'][4:] # JSID is th
e main KEY as JSID are produced every time a session satrts
KeyError: 'JSESSIONID'

URL's are changed.

Hi Shubhamc,

Recently the URL's of way2sms.com has been changed.

self.msg_url='http://site24.way2sms.com/smstoss.action'
self.msg_url='http://site24.way2sms.com/schedulesms.action'
self.msg_left_url='http://site24.way2sms.com/sentSMS?Token='+self.jsid

If someone creates a object and do object.send(number, message). It will return a 200 response, but originally the SMS are not sent.

Here is the current URL structure followed in recently in the site.

http://site21.way2sms.com/main.action?Token=F161C7798A67FBDC9E3873774357290E.w804&section=s

then changes would like this,

self.msg_left_url ='http://site21.way2sms.com/main.action?Token='+self.jsid+'&section='+self.s

Here I'm appending &section= self.s

self.s is a sessionObject, we can't concatenate session object with a str. If this is corrected, then sms can be sent, number of sms sent can also be viewed..

Let's get in touch to discuss more if you wish.

Thanks,
Sanjay

Script is not working with new way2sms

Getting the following error while executing the script -
HTTP Status 405 - Request method 'GET' not supported.

Note - Script needs to be updated to work with the latest way2sms website.

Have observed error code(<Response [404]>) on these line:58 and 60 when I calling this def: q.msgSentToday()

self.t=self.soup.find("div",{"class":"hed"}).h2.text # div element with class "hed" -> h2

Have observed error code(<Response [404]>) on this line:58 => self.q=self.session.get(self.msg_left_url) and got exception on this line:60 self.t=self.soup.find("div",{"class":"hed"}).h2.text
line:58
(<Response [404]>)
line:60
(<class 'AttributeError'>, AttributeError("'NoneType' object has no attribute 'h2'",), <traceback object at 0x0000005524E61208>)

If I comment out q.msgSentToday() it is works fine.

Regards,
Muthu

AttributeError: 'NoneType' object has no attribute 'h2'

Traceback (most recent call last):
  File "C:\Users\Prasad\Desktop\security_serveillance\Server\security_serveillance\test_sms.py", line 9, in <module>
    sent_count = message.msgSentToday()
  File "C:\Users\Prasad\Desktop\security_serveillance\Server\security_serveillance\my_sms.py", line 55, in msgSentToday
    self.t = self.soup.find("div", {"class": "hed"}).h2.text

Getting error way2sms has no sms attribute.

Created a driver code file with all the code to run and send a test message :
way2sms.driver.py

import way2sms

q=way2sms.sms(number,password)

q.send( '9*******', 'test message' )
q.logout();

Then, ran the following command:

$ python3 way2sms.driver.py
Traceback (most recent call last):
  File "way2sms.driver.py", line 3, in <module>
    q=way2sms.sms(7678058981,A7292T)
AttributeError: module 'way2sms' has no attribute 'sms'

Please resolve.
Another query, is the username as same as my phone number; and, do I need to prefix the number with +91 for India's country code?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.