del laf && update docker

This commit is contained in:
RainSun 2020-04-10 20:31:14 +08:00
parent 6c7862ba42
commit b9d85df2c2
11 changed files with 10 additions and 40084 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
logs

View File

@ -23,7 +23,7 @@ flask run --host=0.0.0.0 -p 8001
// beta // beta
flask run --host=127.0.0.1 -p 5005 flask run --host=127.0.0.1 -p 5005
// 启动永久服务 // 启动永久服务
gunicorn coc:app -c gunicorn.conf.py gunicorn coc:cherry -c gunicorn.conf.py
// 查看已启动服务 // 查看已启动服务
pstree -ap|grep gunicorn pstree -ap|grep gunicorn
// 关闭某服务 // 关闭某服务
@ -40,34 +40,6 @@ deactivate
102教务挂了 102教务挂了
200ok 200ok
/api/laf/add
330数据校验失败
331插入数据库失败
/api/laf/del
340数据校验失败
341id不合法
/api/laf/get
350数据校验失败
351lost表获取失败
352found表获取失败
/api/laf/detail
360数据校验失败
361数据不存在
362id不合法
/api/laf/comment
370数据校验失败
371评论数据库修改失败
372回复数据库修改失败
373数据不存在
374id不合法
/api/photo/upload
380图片格式不符
/api/game/schedule/upload /api/game/schedule/upload
400数据校验失败 400数据校验失败
401排名表修改失败 401排名表修改失败
@ -76,39 +48,6 @@ deactivate
410: 数据校验失败 410: 数据校验失败
411排名表获取失败 411排名表获取失败
# lost and found
* /api/laf/add
* data
* title
* content
* create_time
* img_url
* total_addr
* detail_addr
* contact_way > type + content
* 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_id + user_name
* /api/laf/get
* /api/laf/detail
* data
* id
* type
* /api/laf/comment
* data
* user_info > user_id + user_name
* msg
* time
* position
* id
* type
* comment_type
* comment_index
# game # game
* /api/game/schedule/upload * /api/game/schedule/upload
* data * data

View File

@ -2,17 +2,16 @@
import sys import sys
sys.path.append('./lib') sys.path.append('./lib')
# 引入处理函数 # 引入处理函数
from allFunction import manageLogin, managePhoto, manageAdd, manageDel, manageGet, manageDetail, manageComment, manageScheduleUpload, manageScheduleGet from allFunction import manageLogin, manageScheduleUpload, manageScheduleGet
# 引入flask # 引入flask
from flask import Flask, request, session, redirect 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/') @app.route('/api/')
@ -25,42 +24,6 @@ def login():
res = manageLogin(request) res = manageLogin(request)
return res return res
# 上传图片
@app.route('/api/photo/upload', methods=['PUT'], strict_slashes=False)
def upload_photo():
res = managePhoto(request)
return res
# 新增失物招领信息
@app.route('/api/laf/add',methods=['POST'])
def laf_add():
res = manageAdd(request)
return res
# 删除失物招领信息
@app.route('/api/laf/del',methods=['POST'])
def laf_del():
res = manageDel(request)
return res
# 获取全部失物招领信息
@app.route('/api/laf/get',methods=['POST'])
def laf_get():
res = manageGet()
return res
# 获取指定失物招领信息
@app.route('/api/laf/detail',methods=['POST'])
def laf_detail():
res = manageDetail(request)
return res
# 新增评论
@app.route('/api/laf/comment',methods=['POST'])
def laf_comment():
res = manageComment(request)
return res
# 更新课表游戏排名信息 # 更新课表游戏排名信息
@app.route('/api/game/schedule/upload',methods=['POST']) @app.route('/api/game/schedule/upload',methods=['POST'])
def schedule_upload(): def schedule_upload():

2
go.sh
View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
echo start echo start
gunicorn coc:app -c gunicorn.conf.py gunicorn cherry:app -c gunicorn.conf.py

View File

@ -1,11 +1,9 @@
# coding=utf-8 # coding=utf-8
from crawler import connection, getGrade, getSchedule from crawler import connection, getGrade, getSchedule
from mail import sendMail
import json 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 db import addRank, getRank
from db import addLAF, getLost, getFound, getDetail, delLAF, commentLAF, replyLAF, addRank, getRank
# 主函数 # 主函数
# 处理登录操作 data:{cid,pwd,sign} # 处理登录操作 data:{cid,pwd,sign}
@ -22,8 +20,6 @@ def manageLogin(request):
if res['errcode'] == 200: if res['errcode'] == 200:
# 登录成功并进行查询 # 登录成功并进行查询
grade = getGrade(res['ip'], res['s']) grade = getGrade(res['ip'], res['s'])
#if grade['errcode'] == 200:
# sendMail('起来搬砖啦!', '教务系统成绩信息已恢复查询,请查看', ['1144131090@qq.com','nayiyewosile@qq.com'])
schedule = getSchedule(res['ip'], res['s']) schedule = getSchedule(res['ip'], res['s'])
return {'errcode': '200', 'errmsg': 'ok', 'student_name':res['student_name'], 'student_id':res['student_id'], 'grade': grade, 'schedule': schedule} return {'errcode': '200', 'errmsg': 'ok', 'student_name':res['student_name'], 'student_id':res['student_id'], 'grade': grade, 'schedule': schedule}
else: else:
@ -31,89 +27,6 @@ def manageLogin(request):
else: else:
return {'errcode': 100, 'errmsg':'数据校验失败'} return {'errcode': 100, 'errmsg':'数据校验失败'}
# 处理上传的图片
def managePhoto(request):
res = upload_photo(request)
return res
# 处理新增失物招领信息
def manageAdd(request):
# json化应该能当dict用
data_cache = json.loads(request.form['data'])
# MD5校验
checked = checkData(data_cache)
data_cache.pop('sign')
if checked:
return addLAF(data_cache, data_cache['type'])
else:
return {'errcode': 330, 'errmsg': '数据校验失败'}
# 处理删除失物招领信息
def manageDel(request):
# json化应该能当dict用
data_cache = json.loads(request.form['data'])
# MD5校验
checked = checkData(data_cache)
data_cache.pop('sign')
if checked:
return delLAF(data_cache['id'], data_cache['type'], data_cache['user_info'])
else:
return {'errcode': 340, 'errmsg': '数据校验失败'}
# 获取全部失物招领信息
def manageGet():
return {'errcode': 200, 'lost': getLost(), 'found': getFound()}
# 获取指定失物招领信息
def manageDetail(request):
# json化应该能当dict用
data_cache = json.loads(request.form['data'])
# MD5校验
checked = checkData(data_cache)
data_cache.pop('sign')
if checked:
return getDetail(data_cache['id'], data_cache['type'], 361)
else:
return {'errcode': 360, 'errmsg': '数据校验失败'}
# 处理新增评论
def manageComment(request):
# json化应该能当dict用
data_cache = json.loads(request.form['comment_msg'])
# MD5校验
checked = checkData(data_cache)
data_cache.pop('sign')
if checked:
position = data_cache['position']
data = data_cache['data']
if position['comment_type'] == 1:
# 留言
return commentLAF(position['id'], data, position['type'])
elif position['comment_type'] == 2:
# 回复
# 取出信息
laf_cache = getDetail(position['id'], position['type'], 373)
# 错误拦截
if laf_cache['errcode'] != 200:
return laf_cache
# json化失物招领信息
laf_cache = json.loads(laf_cache['detail'])
# 取出comment
comment = laf_cache['comment']
# 如果还没reply过要初始化
if 'reply' not in comment[position['comment_index']]:
comment[position['comment_index']]['reply'] = []
# 将回复信息加入comment
comment[position['comment_index']]['reply'].append(data)
# 覆写comment
return replyLAF(position['id'], comment, position['type'])
else:
# 参数错误
return {'errcode': 370, 'errmsg': '数据校验失败'}
else:
return {'errcode': 370, 'errmsg': '数据校验失败'}
# 处理更新课表游戏排名信息 # 处理更新课表游戏排名信息
def manageScheduleUpload(request): def manageScheduleUpload(request):
# json化应该能当dict用 # json化应该能当dict用
@ -160,11 +73,8 @@ def checkData(data):
# 创建会话 # 创建会话
def connect(data): def connect(data):
loginInfo = loginInterceptor(data) cid = data['cid']
if loginInfo['errcode'] != 200: pwd = data['pwd']
return loginInfo
cid = loginInfo['cid']
pwd = loginInfo['pwd']
# 进行登录 # 进行登录
phone = '' phone = ''
if data.get('phone'): if data.get('phone'):
@ -176,21 +86,3 @@ def connect(data):
except: except:
# 这了就是教务挂了 # 这了就是教务挂了
return {'errcode': 102, 'errmsg':'教务挂了'} 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'}

View File

@ -9,93 +9,13 @@ def col(arg):
conn = MongoClient('mongodb://coc:qlSfefSor5@mongo:27017/coc') conn = MongoClient('mongodb://coc:qlSfefSor5@mongo:27017/coc')
if setting == 'development': if setting == 'development':
arg += '_test' arg += '_test'
if arg == 'lost':
return conn.coc.lost
elif arg == 'found':
return conn.coc.found
elif arg == 'rank': elif arg == 'rank':
return conn.coc.rank return conn.coc.rank
elif arg == 'lost_test':
return conn.coc.lost_test
elif arg == 'found_test':
return conn.coc.found_test
elif arg == 'rank_test': elif arg == 'rank_test':
return conn.coc.rank_test return conn.coc.rank_test
else: else:
return False return False
# 新增失物招领信息
def addLAF(data, add_type):
try:
col(add_type).insert_one(data)
except Exception as e:
# 失败了
return { 'errcode': 331, 'errmsg': '插入数据库失败'}
return {'errcode': 200, 'errmsg': 'ok'}
# 获取全部失物信息
def getLost():
arr = []
try:
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表获取失败'}
return {'errcode': 200, 'arr': json_util.dumps(arr), 'errmsg': 'ok'}
# 获取全部招领信息
def getFound():
arr = []
try:
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表获取失败'}
return {'errcode': 200, 'arr': json_util.dumps(arr), 'errmsg': 'ok'}
# 获取指定失物信息
def getDetail(id, get_type, errcode):
try:
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:
return {'errcode': errcode, 'errmsg': '数据不存在'}
except Exception as e:
# id不合法
return {'errcode': errcode+1, 'errmsg': 'id不合法'}
# 删除某个失物
def delLAF(id, del_type, del_user_info):
try:
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'}
# 向一条记录添加留言
def commentLAF(id, data, laf_type):
try:
col(laf_type).update({"_id": ObjectId(id)},
{'$push': {'comment': data}})
except Exception as e:
# 失败
return {'errcode': 371, 'errmsg': '评论数据库修改失败'}
return {'errcode': 200, 'errmsg': 'ok'}
# 向一条记录添加回复
def replyLAF(id, comment, laf_type):
try:
col(laf_type).update({"_id": ObjectId(id)},
{'$set': {'comment': comment}})
except Exception as e:
# 失败
return {'errcode': 372, 'errmsg': '回复数据库修改失败'}
return {'errcode': 200, 'errmsg': 'ok'}
# 向排名表里增加或覆写数据 # 向排名表里增加或覆写数据
def addRank(nick, count, time): def addRank(nick, count, time):
try: try:

View File

@ -1,32 +0,0 @@
# coding=utf-8
import smtplib
from email.mime.text import MIMEText
# 发送纯文本格式的邮件
def sendMail(title, content, mailto_list):
msg = MIMEText(content, 'plain', 'utf-8')
#发送邮箱地址
sender = '1144131090@qq.com'
#邮箱授权码,非登陆密码
password = 'gmzfcesmbgqhgfjb'
#收件箱地址
#receiver = '19xxxxxxx9@qq.com'
# mailto_list = ['1144131090@qq.com','nayiyewosile@qq.com'] #群发邮箱地址
#smtp服务器
smtp_server = 'smtp.qq.com'
#发送邮箱地址
msg['From'] = sender
#收件箱地址
#msg['To'] = receiver
msg['To'] =';'.join(mailto_list) #发送多人邮件写法
#主题
msg['Subject'] = title
server = smtplib.SMTP(smtp_server,25) # SMTP协议默认端口是25
server.login(sender,password) #ogin()方法用来登录SMTP服务器
server.set_debuglevel(1) #打印出和SMTP服务器交互的所有信息。
server.sendmail(sender,mailto_list,msg.as_string()) #msg.as_string()把MIMEText对象变成str server.quit()
# 第一个参数为发送者,第二个参数为接收者,可以添加多个例如:['hello@163.com','xxx@qq.com',]# 第三个参数为发送的内容
server.quit()

View File

@ -1,31 +0,0 @@
import os
from werkzeug.utils import secure_filename
import datetime
import random
basedir = os.path.abspath(os.path.dirname(__file__))
ALLOWED_EXTENSIONS = set(['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'gif', 'GIF'])
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
def create_uuid(): #生成唯一的图片的名称字符串,防止图片显示时的重名问题
nowTime = datetime.datetime.now().strftime("%Y%m%d%H%M%S") # 生成当前时间
randomNum = random.randint(0, 100) # 生成的随机整数n其中0<=n<=100
if randomNum <= 10:
randomNum = str(0) + str(randomNum)
uniqueNum = str(nowTime) + str(randomNum)
return uniqueNum
def upload_photo(request):
file_dir = os.path.join(basedir, '../upload')
if not os.path.exists(file_dir):
os.makedirs(file_dir)
f = request.files['photo']
if f and allowed_file(f.filename):
fname = secure_filename(f.filename)
ext = fname.rsplit('.', 1)[1]
new_filename = create_uuid() + '.' + ext
f.save(os.path.join(file_dir, new_filename))
return {'errcode': 200, 'filename': new_filename}
else:
return {'errcode': 380, 'errmsg': '图片格式不符'}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

11
test,py
View File

@ -1,11 +0,0 @@
import math
a = math.pow(12.09, 2)
print(a)
b = a / 10
print(b)
c = 3330.97 - b
print(c)
d = math.sqrt(c)
print(d)
e = d / 9
print(e)