-
Notifications
You must be signed in to change notification settings - Fork 29
/
web_interface.py
57 lines (47 loc) · 1.44 KB
/
web_interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import MySQLdb
from flask import Flask, request, jsonify
from main import run_2, run_3
import time
import json
from urllib.parse import unquote
# from cookie import cookie
app = Flask(__name__)
@app.route("/", methods=['POST'])
def run():
# print(request.data)
# 校验数据是否空
if not request.data:
return 'sorry, not get the post data.'
# 获取前端post传入参数
ori_data = request.data.decode('utf-8')
json_data = json.loads(ori_data)
# 校验关键字
keyword = json_data.get('key')
if not keyword:
return 'sorry, please enter isbn number.'
# 安全效验
code = json_data.get('code') # 校验码
if code != 'password':
return 'sorry, error requests!'
# error_cookie = json_data.get('tbcookie') # 淘宝cookie
# if not cookie:
# return 'sorry, please enter taobao cookie.'
# cookie = unquote(cookie).replace('+', ' ')
print('this request time: {} '.format(int(time.time())), keyword, code)
# 数据请求
# try:
# final_data = run_2(keyword=keyword, cookie=cookie)
# except:
# return 'requests error!'
final_data = run_2(keyword=keyword, cookie='')
# 执行数据库数据插入
run_3(final_data, keyword)
return 'true'
if __name__ == '__main__':
# 请在此处定义您的校验码
SAFETY_CODE = 'password'
# host
host = '0.0.0.0'
# port
port = 5001
app.run(host=host, port=port)