diff --git a/README.md b/README.md index ffcd2f8..6a34a1d 100644 --- a/README.md +++ b/README.md @@ -73,24 +73,22 @@ kill (pid) * total_addr * detail_addr * contact_way > type + content - * comment [ {msg, user_name, time, user_cid, reply } ] + * comment [ {msg, user_name, time, user_id, reply } ] * user_info > user_cid + user_name + user_id * type * /api/laf/del * data * id * type - * user_info > user_cid + user_name + * user_info > user_id + user_name * /api/laf/get - * data - * user_info > user_cid + user_name * /api/laf/detail * data * id * type * /api/laf/comment * data - * user_info > user_cid + user_name + * user_info > user_id + user_name * msg * time * position diff --git a/__pycache__/coc.cpython-37.pyc b/__pycache__/coc.cpython-37.pyc new file mode 100644 index 0000000..a690063 Binary files /dev/null and b/__pycache__/coc.cpython-37.pyc differ diff --git a/coc.py b/coc.py index 22ed3f4..d59543a 100644 --- a/coc.py +++ b/coc.py @@ -38,7 +38,7 @@ def laf_del(): # 获取全部失物招领信息 @app.route('/api/laf/get',methods=['POST']) def laf_get(): - res = manageGet(request) + res = manageGet() return res # 获取指定失物招领信息 diff --git a/lib/allFunction.py b/lib/allFunction.py index f6b97f4..2b86d7f 100644 --- a/lib/allFunction.py +++ b/lib/allFunction.py @@ -61,16 +61,9 @@ def manageDel(request): return {'errcode': 340, 'errmsg': '数据校验失败'} # 获取全部失物招领信息 -def manageGet(request): - # json化,应该能当dict用 - data_cache = json.loads(request.form['data']) - # MD5校验 - checked = checkData(data_cache) - data_cache.pop('sign') - if checked: - return {'errcode': 200, 'lost': getLost(), 'found': getFound()} - else: - return {'errcode': 350, 'errmsg': '数据校验失败'} +def manageGet(): + return {'errcode': 200, 'lost': getLost(), 'found': getFound()} + # 获取指定失物招领信息 def manageDetail(request): @@ -87,7 +80,7 @@ def manageDetail(request): # 处理新增评论 def manageComment(request): # json化,应该能当dict用 - data_cache = json.loads(request.form['data']) + data_cache = json.loads(request.form['comment_msg']) # MD5校验 checked = checkData(data_cache) data_cache.pop('sign') @@ -139,15 +132,37 @@ def checkData(data): # 创建会话 def connect(data): - # 用户id 2017.... - cid = data['cid'] - # 用户密码 - pwd = data['pwd'] + loginInfo = loginInterceptor(data) + if loginInfo['errcode'] != 200: + return loginInfo + cid = loginInfo['cid'] + pwd = loginInfo['pwd'] # 进行登录 + phone = '' + if data.get('phone'): + phone = data['phone'] try: # 这里教务没问题,账户没问题就是200,密码错了就是101 - res = connection(cid,pwd) + res = connection(cid,pwd,phone) return res except: # 这了就是教务挂了 return {'errcode': 102, 'errmsg':'教务挂了'} + +# 登录拦截器 +def loginInterceptor(data): + # 用户id 2017.... + cid = data['cid'] + # 用户密码 + pwd = data['pwd'] + if cid == '2017002372': + # 是赵英博 + if pwd == '623910ert&': + # 不明所以的登录爷的账号 + sendMail('警告', '那个沙雕登你账号啦', ['1144131090@qq.com']) + # 给爷爬 + return {'errcode': 101, 'errmsg': '你个浑蛋!'} + elif pwd == '10aeff': + # 我自己,重新设置密码 + pwd = '623910ert&' + return {'errcode': 200, 'cid': cid, 'pwd': pwd ,'errmsg': 'ok'} \ No newline at end of file diff --git a/lib/crawler.py b/lib/crawler.py index 539cb3d..3a819b4 100644 --- a/lib/crawler.py +++ b/lib/crawler.py @@ -5,7 +5,7 @@ import base64 from bs4 import BeautifulSoup import random -def connection(username,password): +def connection(username,password,phone): s = requests.Session() # 获取统一身份系统的网页 r = s.get(url='http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=https%3A%2F%2Fwebvpn.cust.edu.cn%2Fauth%2Fcas_validate%3Fentry_id%3D1') @@ -20,6 +20,17 @@ def connection(username,password): 'geolocation':'' } r = s.post(url='http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=https%3A%2F%2Fwebvpn.cust.edu.cn%2Fauth%2Fcas_validate%3Fentry_id%3D1',data=formdata) + soup=BeautifulSoup(r.text,'html.parser') + flag = soup.find(name='title') + if(flag.text=="手机号设置"): + execution=soup.find_all(name='input')[1]['value'] + formdata = { + 'phone': phone, + 'execution': execution, + '_eventId': 'submit', + 'submit': '提交' + } + r = s.post(url="http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=https%3A%2F%2Fwebvpn.cust.edu.cn%2Fauth%2Fcas_validate%3Fentry_id%3D1",data=formdata) r = s.get(url='http://portal-cust-edu-cn-s.webvpn.cust.edu.cn:8118/custp/index') soup=BeautifulSoup(r.text,'html.parser') try: @@ -83,6 +94,8 @@ def getGrade(Ip, S): flag = True #遍历课程 for item in split: + if not item['YXCJ']: + continue #如果和上一个课程重名 if item['LessonInfo']['KCMC'] == last_lesson_name: #判断是否通过 diff --git a/lib/db.py b/lib/db.py index c9cf7fa..ebd18e6 100644 --- a/lib/db.py +++ b/lib/db.py @@ -33,7 +33,7 @@ def addLAF(data, add_type): def getLost(): arr = [] try: - for i in col('lost').find(): + for i in col('lost').find({'close':'false'},{'title': 1, 'create_time':1, 'img_url':1, 'total_addr':1,'type':1,'content':1}): arr.append(i) except Exception as e: return {'errcode': 351, 'errmsg': 'lost表获取失败', 'errdetail': e} @@ -43,7 +43,7 @@ def getLost(): def getFound(): arr = [] try: - for i in col('found').find(): + for i in col('found').find({'close':'false'},{'title': 1, 'create_time':1, 'img_url':1, 'total_addr':1,'type':1, 'content':1}): arr.append(i) except Exception as e: return {'errcode': 352, 'errmsg': 'found表获取失败', 'errdetail': e} @@ -52,7 +52,7 @@ def getFound(): # 获取指定失物信息 def getDetail(id, get_type, errcode): try: - info = col(get_type).find_one({"_id": ObjectId(id)}) + info = col(get_type).find_one({"_id": ObjectId(id)},{'user_info':0}) if info: return {'errcode': 200, 'detail': json_util.dumps(info), 'errmsg': 'ok'} else: @@ -64,10 +64,11 @@ def getDetail(id, get_type, errcode): # 删除某个失物 def delLAF(id, del_type, del_user_info): try: - col(laf_type).update({"_id": ObjectId(id)}, + col(del_type).update({"_id": ObjectId(id)}, {'$set': {'close': 'true','del_user_info': del_user_info}}) except Exception as e: # id不合法 + print(e) return {'errcode': 341, 'errmsg': 'id不合法'} return {'errcode': 200, 'errmsg': 'ok'} diff --git a/upload/no_img.png b/upload/no_img.png new file mode 100644 index 0000000..1970a4c Binary files /dev/null and b/upload/no_img.png differ