update ticket

This commit is contained in:
RainSun 2020-06-26 22:34:33 +08:00
parent 67fa9d87b7
commit 27222f6722
4 changed files with 32 additions and 17 deletions

View File

@ -25,7 +25,7 @@ flask run --host=0.0.0.0 -p 8001
// beta
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
// 关闭某服务

View File

@ -60,7 +60,7 @@ class Crawler(object):
return ('账号或者密码错误', 510)
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)
ticket = r.headers['Location'][68:]
ticket = r.headers['Location'][72:]
asp_net_sessionid_param = {'Ticket': ticket, 'Url': 'http://' +
self.__ip[0] + '.' + self.__ip[1] + '.' + self.__ip[2] + '.' + self.__ip[3] + ':8080/welcome'}
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] +
'-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'))
# 提示未建立教务信息
if data['state'] == 1:
return (data['message'], 513)
self.__student_name = data['data']['StudentDto']['XM']
self.__student_id = data['data']['StudentDto']['XH']
return ('ok', 200)
@ -204,7 +207,7 @@ class Crawler(object):
last_term_grade_list.append({
'title': item['LessonInfo']['KCMC'],
'credit': item['XF'],
'grade': item['ShowYXCJ'],
'grade': item['YXCJ'],
'kill': 'yes' if (item['YXCJ'] >= 60) else 'no',
'class': item['KSXZ']
})

View File

@ -9,17 +9,17 @@ class TestCrawler(unittest.TestCase):
self.assertEqual(c.connection(), ('ok', 200))
# 测试获取成绩
def test_grade(self):
self.assertEqual(c.getGrade(), ('ok', 200))
# def test_grade(self):
# self.assertEqual(c.getGrade(), ('ok', 200))
# 测试获取课表
def test_schedule(self):
self.assertEqual(c.getSchedule(), ('ok', 200))
# def test_schedule(self):
# self.assertEqual(c.getSchedule(), ('ok', 200))
# 测试返回信息
def test_getData(self):
get_res = c.getData()
self.assertEqual(get_res['errcode'], '200')
# def test_getData(self):
# get_res = c.getData()
# self.assertEqual(get_res['errcode'], '200')
if __name__ == '__main__':
unittest.main()

View File

@ -3,23 +3,33 @@ from bson import ObjectId, json_util
# 主环境 (生产环境为production开发环境为development)
setting = 'development'
env = 'coc'
# 获取数据集
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':
arg += '_test'
if arg == 'rank':
return conn.cherry.rank
return conn[env].rank
elif arg == 'rank_test':
return conn.cherry.rank_test
return conn[env].rank_test
else:
return False
# 向排名表里增加或覆写数据
def addRank(nick, count, time):
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})
except Exception as e:
# 失败
@ -27,15 +37,17 @@ def addRank(nick, count, time):
return {'errcode': 200, 'errmsg': 'ok'}
# 获取排名表所有信息除了id
def getRank():
time_rank = []
count_rank = []
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)
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)
except Exception as e:
print(e)
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'}