forked from kimixuchen/GymAutoOrder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebLogin_V1.0.py
125 lines (105 loc) · 3.48 KB
/
WebLogin_V1.0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding:utf8 -*-
"""
程序在当晚12点前启动,第二天早晨预约2天后的场地
2015-12-23 18:38:05
xuchen
"""
import urllib2
import urllib
import cookielib
import gzip
from PIL import Image
from StringIO import StringIO
import zlib
import os
import datetime
import time
import thread
import PicProcess
DATEFORMAT_Ymd = '%Y-%m-%d'
DATEFORMAT_YmdHMS = '%Y-%m-%d %H:%M:%S'
class OrderRobot:
def __init__(self):
self.headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36'
}
self.loginUrl = 'http://myold.seu.edu.cn/userPasswordValidate.portal'
self.validateimageUrl = 'http://yuyue.seu.edu.cn/eduplus/control/validateimage'
self.postOrderUrl = 'http://yuyue.seu.edu.cn/eduplus/order/order/insertOredr.do?sclId=1'
today = datetime.date.today()
self.orderday = today + datetime.timedelta(days=3)
self.cookie = cookielib.CookieJar()
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
self.username = raw_input('username>')
self.password = raw_input('password>')
self.time = {'6':' 18:00-19:00', '7':' 19:00-20:00', '8':' 20:00-21:00'}
self.t = raw_input('starttime: \n6---18:00-19:00 \n7---19:00-20:00 \n8---20:00-21:00\n>')
self.starttime = self.time[self.t]
self.loginPostdata=urllib.urlencode({
'Login.Token1':self.username,
'Login.Token2':self.password,
'goto':'http://myold.seu.edu.cn/loginSuccess.portal',
'gotoOnFail':'http://myold.seu.edu.cn/loginFailure.portal'
})
self.friendId = '75496'
self.islogin = False
def setFriend(self, name):
self.friendId = self.friends[name]
def login(self):
req = urllib2.Request(
url = self.loginUrl,
data = self.loginPostdata,
headers = self.headers
)
thread.start_new_thread(self.loginthread, (1,req))
thread.start_new_thread(self.loginthread, (2,req))
thread.start_new_thread(self.loginthread, (3,req))
def loginthread(self, no, req):
print('loginthread:%d\n' % no)
result = self.opener.open(req)
for c in self.cookie:
print 'cookie: '+c.name
print 'value: '+c.value
self.islogin = True
def orderBadminton(self):
validateResult = self.opener.open(self.validateimageUrl)
validateNum = PicProcess.getResutlFromStr(validateResult.read())
orderPostdata = urllib.urlencode({
'orderVO.useTime':self.orderday.strftime(DATEFORMAT_Ymd)+self.starttime,
'orderVO.itemId':'10',
'orderVO.useMode':'2',
'useUserIds':'78749',
'orderVO.phone':'13736542156',
'orderVO.remark':'',
'validateCode':validateNum
})
req = urllib2.Request(
url = self.postOrderUrl,
data = orderPostdata,
headers = self.headers
)
result = self.opener.open(req)
return result.read()
now = datetime.datetime.now()
nextDay = now + datetime.timedelta(days=1)
#登陆时间 8:00:00s
loginTime = datetime.datetime(nextDay.year, nextDay.month, nextDay.day , 8, 0, 0)
#登出时间 8:04:00s
exitTime = datetime.datetime(nextDay.year, nextDay.month, nextDay.day , 8, 4, 0)
myOrderRobot = OrderRobot()
while(now < loginTime):
now = datetime.datetime.now()
time.sleep(1)
print "Login Time: %s Now: %s Target Time: %s" % (loginTime, now, myOrderRobot.orderday)
myOrderRobot.login()
isSuccess = False
while not myOrderRobot.islogin:
continue
while(not(isSuccess) and now < exitTime):
now = datetime.datetime.now()
print isSuccess
result = myOrderRobot.orderBadminton()
if result == 'success':
isSuccess = True
print 'succcess'
time.sleep(1)