Merge branch 'master' of git.code.tencent.com:cust-developers/cust

This commit is contained in:
lijingwei233 2020-02-29 20:28:57 +08:00
commit 944220c206
9 changed files with 118 additions and 18 deletions

4
.gitignore vendored
View File

@ -1,4 +1,2 @@
lib/__pycache__/allFunction.cpython-37.pyc __pycache__
lib/__pycache__/crawler.cpython-37.pyc
lib/__pycache__/mail.cpython-37.pyc
.vscode/settings.json .vscode/settings.json

View File

@ -14,17 +14,22 @@ pip install requests
pip install bs4 pip install bs4
pip install gunicorn pip install gunicorn
pip install pymongo pip install pymongo
pip install flask_cors
// 设置全局变量 // 设置全局变量
export FLASK_APP=coc.py export FLASK_APP=coc.py
export FLASK_ENV=development export FLASK_ENV=development
// 启动临时服务 // 启动临时服务
flask run --host=0.0.0.0 -p 8001 flask run --host=0.0.0.0 -p 8001
// beta
flask run --host=127.0.0.1 -p 5005
// 启动永久服务 // 启动永久服务
gunicorn coc:app -c gunicorn.conf.py gunicorn coc:app -c gunicorn.conf.py
// 查看已启动服务 // 查看已启动服务
pstree -ap|grep gunicorn pstree -ap|grep gunicorn
// 关闭某服务 // 关闭某服务
kill (pid) kill (pid)
//关闭venv
deactivate
``` ```
## 错误代码一览 ## 错误代码一览
@ -63,6 +68,14 @@ kill (pid)
/api/photo/upload /api/photo/upload
380图片格式不符 380图片格式不符
/api/game/schedule/upload
400数据校验失败
401排名表修改失败
/api/game/schedule/get
410: 数据校验失败
411排名表获取失败
# lost and found # lost and found
* /api/laf/add * /api/laf/add
* data * data
@ -95,4 +108,14 @@ kill (pid)
* id * id
* type * type
* comment_type * comment_type
* comment_index * comment_index
# game
* /api/game/schedule/upload
* data
* nick
* count
* time
* sign
* /api/game/schedule/get
* data
* sign

Binary file not shown.

36
coc.py
View File

@ -2,16 +2,22 @@
import sys import sys
sys.path.append('./lib') sys.path.append('./lib')
# 引入处理函数 # 引入处理函数
from allFunction import manageLogin, managePhoto, manageAdd, manageDel, manageGet, manageDetail, manageComment from allFunction import manageLogin, managePhoto, manageAdd, manageDel, manageGet, manageDetail, manageComment, manageScheduleUpload, manageScheduleGet
# 引入flask # 引入flask
from flask import Flask, request, session from flask import Flask, request, session, redirect
# 初始化app # 初始化app
app = Flask(__name__) app = Flask(__name__)
# 引入跨域访问处理模块 # 引入跨域访问处理模块
# from flask_cors import CORS from flask_cors import CORS
# 取消跨域访问限制,方便本地测试 注册CORS, "/*" 允许访问所有api # 取消跨域访问限制,方便本地测试 注册CORS, "/*" 允许访问所有api
# CORS(app, resources=r'/*') CORS(app, resources=r'/*')
# 测试用根路由
@app.route('/api/')
def sayHello():
return 'Hello! Glad to serve you.'
# 登录接口前端提供cid和pwd包装在data里边然后md5校验也就是data:{cid,pwd,sign} # 登录接口前端提供cid和pwd包装在data里边然后md5校验也就是data:{cid,pwd,sign}
@app.route('/api/login',methods=['POST']) @app.route('/api/login',methods=['POST'])
@ -55,10 +61,24 @@ def laf_comment():
res = manageComment(request) res = manageComment(request)
return res return res
# 审核 # 更新课表游戏排名信息
@app.route('/api/shenhe') @app.route('/api/game/schedule/upload',methods=['POST'])
def laf_shenhe(): def schedule_upload():
data = manageGet() res = manageScheduleUpload(request)
return res
# 获取课表游戏排名信息
@app.route('/api/game/schedule/get',methods=['POST'])
def schedule_get():
res = manageScheduleGet(request)
return res
# 访问拦截器转发到根路由
@app.errorhandler(404)
def miss(e):
return redirect('/api')
# 本地运行启动
if __name__ == '__main__': if __name__ == '__main__':
app.debug = True app.debug = True
app.run() app.run()

View File

@ -1,7 +1,10 @@
# 并行工作线程数 # 并行工作线程数
workers = 4 workers = 4
# 监听内网端口5000【按需要更改】 # 监听内网端口5000【按需要更改】
bind = '127.0.0.1:5003' # coc
# bind = '127.0.0.1:5003'
# beta
bind = '127.0.0.1:5005'
# 设置守护进程【关闭连接时,程序仍在运行】 # 设置守护进程【关闭连接时,程序仍在运行】
daemon = True daemon = True
# 设置超时时间120s默认为30s。按自己的需求进行设置 # 设置超时时间120s默认为30s。按自己的需求进行设置

Binary file not shown.

View File

@ -5,7 +5,7 @@ import json
from hashlib import md5 from hashlib import md5
from urllib.parse import urlencode, unquote_plus from urllib.parse import urlencode, unquote_plus
from photoUpload import upload_photo from photoUpload import upload_photo
from db import addLAF, getLost, getFound, getDetail, delLAF, commentLAF, replyLAF from db import addLAF, getLost, getFound, getDetail, delLAF, commentLAF, replyLAF, addRank, getRank
# 主函数 # 主函数
# 处理登录操作 data:{cid,pwd,sign} # 处理登录操作 data:{cid,pwd,sign}
@ -114,6 +114,34 @@ def manageComment(request):
else: else:
return {'errcode': 370, 'errmsg': '数据校验失败'} return {'errcode': 370, 'errmsg': '数据校验失败'}
# 处理更新课表游戏排名信息
def manageScheduleUpload(request):
# json化应该能当dict用
data_cache = json.loads(request.form['data'])
# MD5校验
checked = checkData(data_cache)
data_cache.pop('sign')
if checked:
add_res = addRank( data_cache['nick'], data_cache['count'], data_cache['time'])
return add_res
else:
return {'errcode': 400, 'errmsg': '数据校验失败'}
# 处理获取课表游戏排名信息
def manageScheduleGet(request):
# json化应该能当dict用
data_cache = json.loads(request.form['data'])
# MD5校验
checked = checkData(data_cache)
data_cache.pop('sign')
if checked:
# 获取排名表
get_res = getRank()
return get_res
else:
return {'errcode': 400, 'errmsg': '数据校验失败'}
# 工具函数 # 工具函数
# MD5 校验 # MD5 校验

View File

@ -13,10 +13,14 @@ def col(arg):
return conn.coc.lost return conn.coc.lost
elif arg == 'found': elif arg == 'found':
return conn.coc.found return conn.coc.found
elif arg == 'rank':
return conn.coc.rank
elif arg == 'lost_test': elif arg == 'lost_test':
return conn.coc.lost_test return conn.coc.lost_test
elif arg == 'found_test': elif arg == 'found_test':
return conn.coc.found_test return conn.coc.found_test
elif arg == 'rank_test':
return conn.coc.rank_test
else: else:
return False return False
@ -26,7 +30,7 @@ def addLAF(data, add_type):
col(add_type).insert_one(data) col(add_type).insert_one(data)
except Exception as e: except Exception as e:
# 失败了 # 失败了
return { 'errcode': 331, 'errmsg': '插入数据库失败', 'errdetail': e} return { 'errcode': 331, 'errmsg': '插入数据库失败'}
return {'errcode': 200, 'errmsg': 'ok'} return {'errcode': 200, 'errmsg': 'ok'}
# 获取全部失物信息 # 获取全部失物信息
@ -36,7 +40,7 @@ def getLost():
for i in col('lost').find({'close':'false'},{'title': 1, 'create_time':1, 'img_url':1, 'total_addr':1,'type':1,'content':1}): 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) arr.append(i)
except Exception as e: except Exception as e:
return {'errcode': 351, 'errmsg': 'lost表获取失败', 'errdetail': e} return {'errcode': 351, 'errmsg': 'lost表获取失败'}
return {'errcode': 200, 'arr': json_util.dumps(arr), 'errmsg': 'ok'} return {'errcode': 200, 'arr': json_util.dumps(arr), 'errmsg': 'ok'}
# 获取全部招领信息 # 获取全部招领信息
@ -46,7 +50,7 @@ def getFound():
for i in col('found').find({'close':'false'},{'title': 1, 'create_time':1, 'img_url':1, 'total_addr':1,'type':1, 'content':1}): 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) arr.append(i)
except Exception as e: except Exception as e:
return {'errcode': 352, 'errmsg': 'found表获取失败', 'errdetail': e} return {'errcode': 352, 'errmsg': 'found表获取失败'}
return {'errcode': 200, 'arr': json_util.dumps(arr), 'errmsg': 'ok'} return {'errcode': 200, 'arr': json_util.dumps(arr), 'errmsg': 'ok'}
# 获取指定失物信息 # 获取指定失物信息
@ -59,7 +63,7 @@ def getDetail(id, get_type, errcode):
return {'errcode': errcode, 'errmsg': '数据不存在'} return {'errcode': errcode, 'errmsg': '数据不存在'}
except Exception as e: except Exception as e:
# id不合法 # id不合法
return {'errcode': errcode+1, 'errmsg': 'id不合法', 'errdetail': e} return {'errcode': errcode+1, 'errmsg': 'id不合法'}
# 删除某个失物 # 删除某个失物
def delLAF(id, del_type, del_user_info): def delLAF(id, del_type, del_user_info):
@ -91,3 +95,27 @@ def replyLAF(id, comment, laf_type):
# 失败 # 失败
return {'errcode': 372, 'errmsg': '回复数据库修改失败'} return {'errcode': 372, 'errmsg': '回复数据库修改失败'}
return {'errcode': 200, 'errmsg': 'ok'} return {'errcode': 200, 'errmsg': 'ok'}
# 向排名表里增加或覆写数据
def addRank(nick, count, time):
try:
# col('rank').update({"cid":cid}, {'$setOnInsert':{"nick":nick}, '$set':{"grade":grade,"time":time}}, {'upsert':'true'})
col('rank').insert_one({"count":count,"time":time,"nick":nick})
except Exception as e:
# 失败
return {'errcode': 401, 'errmsg': '排名表修改失败'}
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):
time_rank.append(i)
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'}