update ticket
This commit is contained in:
parent
67fa9d87b7
commit
27222f6722
@ -25,7 +25,7 @@ flask run --host=0.0.0.0 -p 8001
|
|||||||
// beta
|
// beta
|
||||||
flask run --host=127.0.0.1 -p 6000
|
flask run --host=127.0.0.1 -p 6000
|
||||||
// 启动永久服务
|
// 启动永久服务
|
||||||
gunicorn coc:cherry -c gunicorn.conf.py
|
gunicorn cherry:app -c gunicorn.conf.py
|
||||||
// 查看已启动服务
|
// 查看已启动服务
|
||||||
pstree -ap|grep gunicorn
|
pstree -ap|grep gunicorn
|
||||||
// 关闭某服务
|
// 关闭某服务
|
||||||
|
@ -60,7 +60,7 @@ class Crawler(object):
|
|||||||
return ('账号或者密码错误', 510)
|
return ('账号或者密码错误', 510)
|
||||||
r = self.__session.get(url='http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=http://' +
|
r = self.__session.get(url='http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=http://' +
|
||||||
self.__ip[0] + '.' + self.__ip[1] + '.' + self.__ip[2] + '.' + self.__ip[3] + ':8080/welcome', allow_redirects=False)
|
self.__ip[0] + '.' + self.__ip[1] + '.' + self.__ip[2] + '.' + self.__ip[3] + ':8080/welcome', allow_redirects=False)
|
||||||
ticket = r.headers['Location'][68:]
|
ticket = r.headers['Location'][72:]
|
||||||
asp_net_sessionid_param = {'Ticket': ticket, 'Url': 'http://' +
|
asp_net_sessionid_param = {'Ticket': ticket, 'Url': 'http://' +
|
||||||
self.__ip[0] + '.' + self.__ip[1] + '.' + self.__ip[2] + '.' + self.__ip[3] + ':8080/welcome'}
|
self.__ip[0] + '.' + self.__ip[1] + '.' + self.__ip[2] + '.' + self.__ip[3] + ':8080/welcome'}
|
||||||
asp_net_sessionid_param = base64.b64encode(
|
asp_net_sessionid_param = base64.b64encode(
|
||||||
@ -70,6 +70,9 @@ class Crawler(object):
|
|||||||
r = self.__session.post(url='http://' + self.__ip[0] + '-' + self.__ip[1] + '-' + self.__ip[2] + '-' + self.__ip[3] +
|
r = self.__session.post(url='http://' + self.__ip[0] + '-' + self.__ip[1] + '-' + self.__ip[2] + '-' + self.__ip[3] +
|
||||||
'-8080-p.webvpn.cust.edu.cn:8118/api/LoginApi/LGSSOLocalLogin?sf_request_type=ajax', data=json.dumps(asp_net_sessionid_param), headers=headers)
|
'-8080-p.webvpn.cust.edu.cn:8118/api/LoginApi/LGSSOLocalLogin?sf_request_type=ajax', data=json.dumps(asp_net_sessionid_param), headers=headers)
|
||||||
data = json.loads(r.content.decode('utf-8'))
|
data = json.loads(r.content.decode('utf-8'))
|
||||||
|
# 提示未建立教务信息
|
||||||
|
if data['state'] == 1:
|
||||||
|
return (data['message'], 513)
|
||||||
self.__student_name = data['data']['StudentDto']['XM']
|
self.__student_name = data['data']['StudentDto']['XM']
|
||||||
self.__student_id = data['data']['StudentDto']['XH']
|
self.__student_id = data['data']['StudentDto']['XH']
|
||||||
return ('ok', 200)
|
return ('ok', 200)
|
||||||
@ -204,7 +207,7 @@ class Crawler(object):
|
|||||||
last_term_grade_list.append({
|
last_term_grade_list.append({
|
||||||
'title': item['LessonInfo']['KCMC'],
|
'title': item['LessonInfo']['KCMC'],
|
||||||
'credit': item['XF'],
|
'credit': item['XF'],
|
||||||
'grade': item['ShowYXCJ'],
|
'grade': item['YXCJ'],
|
||||||
'kill': 'yes' if (item['YXCJ'] >= 60) else 'no',
|
'kill': 'yes' if (item['YXCJ'] >= 60) else 'no',
|
||||||
'class': item['KSXZ']
|
'class': item['KSXZ']
|
||||||
})
|
})
|
||||||
|
@ -9,17 +9,17 @@ class TestCrawler(unittest.TestCase):
|
|||||||
self.assertEqual(c.connection(), ('ok', 200))
|
self.assertEqual(c.connection(), ('ok', 200))
|
||||||
|
|
||||||
# 测试获取成绩
|
# 测试获取成绩
|
||||||
def test_grade(self):
|
# def test_grade(self):
|
||||||
self.assertEqual(c.getGrade(), ('ok', 200))
|
# self.assertEqual(c.getGrade(), ('ok', 200))
|
||||||
|
|
||||||
# 测试获取课表
|
# 测试获取课表
|
||||||
def test_schedule(self):
|
# def test_schedule(self):
|
||||||
self.assertEqual(c.getSchedule(), ('ok', 200))
|
# self.assertEqual(c.getSchedule(), ('ok', 200))
|
||||||
|
|
||||||
# 测试返回信息
|
# 测试返回信息
|
||||||
def test_getData(self):
|
# def test_getData(self):
|
||||||
get_res = c.getData()
|
# get_res = c.getData()
|
||||||
self.assertEqual(get_res['errcode'], '200')
|
# self.assertEqual(get_res['errcode'], '200')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
26
lib/db.py
26
lib/db.py
@ -3,23 +3,33 @@ from bson import ObjectId, json_util
|
|||||||
|
|
||||||
# 主环境 (生产环境为production,开发环境为development)
|
# 主环境 (生产环境为production,开发环境为development)
|
||||||
setting = 'development'
|
setting = 'development'
|
||||||
|
env = 'coc'
|
||||||
|
|
||||||
# 获取数据集
|
# 获取数据集
|
||||||
|
|
||||||
|
|
||||||
def col(arg):
|
def col(arg):
|
||||||
conn = MongoClient('mongodb://cherry:fR1jW2xG3bE9@mongo:27017/cherry')
|
if env == 'coc':
|
||||||
|
conn = MongoClient('mongodb://coc:qlSfefSor5@0.0.0.0:12236/coc')
|
||||||
|
else:
|
||||||
|
conn = MongoClient('mongodb://cherry:fR1jW2xG3bE9@mongo:27017/cherry')
|
||||||
|
|
||||||
if setting == 'development':
|
if setting == 'development':
|
||||||
arg += '_test'
|
arg += '_test'
|
||||||
if arg == 'rank':
|
if arg == 'rank':
|
||||||
return conn.cherry.rank
|
return conn[env].rank
|
||||||
elif arg == 'rank_test':
|
elif arg == 'rank_test':
|
||||||
return conn.cherry.rank_test
|
return conn[env].rank_test
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 向排名表里增加或覆写数据
|
# 向排名表里增加或覆写数据
|
||||||
|
|
||||||
|
|
||||||
def addRank(nick, count, time):
|
def addRank(nick, count, time):
|
||||||
try:
|
try:
|
||||||
col('rank').update({"cid":cid}, {'$setOnInsert':{"nick":nick}, '$set':{"count":count,"time":time}}, {'upsert':'true'})
|
col('rank').update({"cid": cid}, {'$setOnInsert': {"nick": nick}, '$set': {
|
||||||
|
"count": count, "time": time}}, {'upsert': 'true'})
|
||||||
# col('rank').insert_one({"count":count,"time":time,"nick":nick})
|
# col('rank').insert_one({"count":count,"time":time,"nick":nick})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 失败
|
# 失败
|
||||||
@ -27,15 +37,17 @@ def addRank(nick, count, time):
|
|||||||
return {'errcode': 200, 'errmsg': 'ok'}
|
return {'errcode': 200, 'errmsg': 'ok'}
|
||||||
|
|
||||||
# 获取排名表所有信息(除了id)
|
# 获取排名表所有信息(除了id)
|
||||||
|
|
||||||
|
|
||||||
def getRank():
|
def getRank():
|
||||||
time_rank = []
|
time_rank = []
|
||||||
count_rank = []
|
count_rank = []
|
||||||
try:
|
try:
|
||||||
for i in col('rank').find({},{"_id":0}).sort([("time",1),("count",1)]).limit(10):
|
for i in col('rank').find({}, {"_id": 0}).sort([("time", 1), ("count", 1)]).limit(10):
|
||||||
time_rank.append(i)
|
time_rank.append(i)
|
||||||
for i in col('rank').find({},{"_id":0}).sort([("count",1),("time",1)]).limit(10):
|
for i in col('rank').find({}, {"_id": 0}).sort([("count", 1), ("time", 1)]).limit(10):
|
||||||
count_rank.append(i)
|
count_rank.append(i)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return {'errcode': 411, 'errmsg': '排名表获取失败'}
|
return {'errcode': 411, 'errmsg': '排名表获取失败'}
|
||||||
return {'errcode': 200, 'time_rank': time_rank, 'count_rank': count_rank, 'errmsg': 'ok'}
|
return {'errcode': 200, 'time_rank': time_rank, 'count_rank': count_rank, 'errmsg': 'ok'}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user