|
3 | 3 | import cookielib |
4 | 4 | from getpass import getpass |
5 | 5 | import sys |
6 | | - |
| 6 | + |
7 | 7 | try: |
8 | 8 | input = raw_input |
9 | 9 | except NameError: |
|
12 | 12 | username = input('Enter mobile number:') |
13 | 13 | passwd = getpass() |
14 | 14 | message = input('Enter Message:') |
15 | | -#Fill the list with Recipients |
16 | | -x=input('Enter Mobile numbers seperated with comma:') |
17 | | -num=x.split(',') |
| 15 | +# Fill the list with Recipients |
| 16 | +x = input('Enter Mobile numbers seperated with comma:') |
| 17 | +num = x.split(',') |
18 | 18 | message = "+".join(message.split(' ')) |
19 | | - |
20 | | -#Logging into the SMS Site |
| 19 | + |
| 20 | +# Logging into the SMS Site |
21 | 21 | url = 'http://site24.way2sms.com/Login1.action?' |
22 | | -data = 'username='+username+'&password='+passwd+'&Submit=Sign+in' |
23 | | - |
24 | | -#For Cookies: |
| 22 | +data = 'username={0}&password={1}&Submit=Sign+in'.format(username, passwd) |
| 23 | + |
| 24 | +# For Cookies: |
25 | 25 | cj = cookielib.CookieJar() |
26 | 26 | opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) |
27 | | - |
| 27 | + |
28 | 28 | # Adding Header detail: |
29 | | -opener.addheaders = [('User-Agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36')] |
30 | | - |
| 29 | +opener.addheaders = [('User-Agent', |
| 30 | + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 ' |
| 31 | + 'Safari/537.36')] |
| 32 | + |
31 | 33 | try: |
32 | 34 | usock = opener.open(url, data) |
33 | 35 | except IOError: |
34 | 36 | print("Error while logging in.") |
35 | 37 | sys.exit(1) |
36 | | - |
37 | | - |
| 38 | + |
38 | 39 | jession_id = str(cj).split('~')[1].split(' ')[0] |
39 | 40 | send_sms_url = 'http://site24.way2sms.com/smstoss.action?' |
40 | 41 |
|
41 | | -opener.addheaders = [('Referer', 'http://site25.way2sms.com/sendSMS?Token='+jession_id)] |
42 | | - |
| 42 | +opener.addheaders = [('Referer', 'http://site25.way2sms.com/sendSMS?Token=%s' % jession_id)] |
| 43 | + |
43 | 44 | try: |
44 | 45 | for number in num: |
45 | | - send_sms_data = 'ssaction=ss&Token='+jession_id+'&mobile='+number+'&message='+message+'&msgLen=136' |
46 | | - sms_sent_page = opener.open(send_sms_url,send_sms_data) |
| 46 | + send_sms_data = 'ssaction=ss&Token={0}&mobile={1}&message={2}&msgLen=136'.format(jession_id, number, message) |
| 47 | + sms_sent_page = opener.open(send_sms_url, send_sms_data) |
47 | 48 | except IOError: |
48 | 49 | print("Error while sending message") |
49 | | - |
50 | | -sys.exit(1) |
| 50 | + |
51 | 51 | print("SMS has been sent.") |
| 52 | +sys.exit(1) |
0 commit comments