You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.8 KiB
75 lines
1.8 KiB
from flask import Flask, request
|
|
from flask_cors import CORS
|
|
import json
|
|
import pymysql
|
|
|
|
app = Flask(__name__)
|
|
CORS(app, resources=r'/*')
|
|
|
|
|
|
class Model:
|
|
def __init__(self):
|
|
self.db = pymysql.connect(
|
|
host='106.52.105.247',
|
|
port=3306,
|
|
user='root',
|
|
passwd='332638qaz',
|
|
db='yiban',
|
|
charset='utf8'
|
|
)
|
|
self.cursor = self.db.cursor()
|
|
|
|
def insert(self, qq, cookie):
|
|
self.cursor.execute("SELECT * FROM yiban WHERE qq=%d;" % qq)
|
|
data = self.cursor.fetchall()
|
|
print(data)
|
|
if len(data) == 0:
|
|
self.cursor.execute(
|
|
"insert into yiban values (%d,'%s');" % (qq, cookie))
|
|
self.db.commit()
|
|
return 0
|
|
else:
|
|
self.cursor.execute("UPDATE yiban SET cookie='%s' WHERE qq=%d;" % (cookie, qq))
|
|
self.db.commit()
|
|
return 1
|
|
|
|
|
|
model = Model()
|
|
|
|
|
|
@app.route('/submit', methods=['POST'])
|
|
def submit():
|
|
data = request.get_data().decode()
|
|
data = json.loads(data)
|
|
try:
|
|
qq = int(data['qq'])
|
|
except:
|
|
data = {
|
|
'code': 100,
|
|
'msg': '请输入合法QQ号'
|
|
}
|
|
data = json.dumps(data)
|
|
return data
|
|
|
|
try:
|
|
cookie = data['cookie']
|
|
except:
|
|
data = {'code': 101, 'msg': '请输入合法的cookie'}
|
|
data = json.dumps(data)
|
|
return data
|
|
|
|
try:
|
|
res = model.insert(qq, cookie)
|
|
if res == 0:
|
|
msg = '开始刷取易班网薪'
|
|
else:
|
|
msg = 'cookie 更新成功'
|
|
data = {'code': 104, 'msg': msg}
|
|
except Exception as e:
|
|
print(e)
|
|
data = {'code': 103, 'msg': '发生未知错误,请重新检查输入'}
|
|
return data
|
|
|
|
|
|
app.run('0.0.0.0', port=7777)
|