|
@@ -1,14 +1,16 @@
|
|
|
import json
|
|
|
+import requests
|
|
|
from flask import Flask, request
|
|
|
from flask import jsonify
|
|
|
from common.db.mysql_help import MysqlHelper
|
|
|
+from user_spider.user_info import *
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
app.config['JSON_AS_ASCII'] = False
|
|
|
|
|
|
|
|
|
|
|
|
-@app.route("/v1/source/getinfo", methods=["GET"])
|
|
|
+@app.route("/v1/crawler/source/getall", methods=["GET"])
|
|
|
def getSource():
|
|
|
|
|
|
get_data = request.args.to_dict()
|
|
@@ -30,21 +32,36 @@ def getSource():
|
|
|
return jsonify({'return_code': '200', 'result': source_list})
|
|
|
|
|
|
|
|
|
-@app.route("/v1/task/insert", methods=["POST"])
|
|
|
-def inerttask():
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+@app.route("/v1/crawler/task/insert", methods=["POST"])
|
|
|
+def insertTask():
|
|
|
+ data = request.form
|
|
|
+ outer_info = data.get(('spider_link'))
|
|
|
+ source = data.get('source')
|
|
|
+ exist_outer_info = list()
|
|
|
+ for link in outer_info:
|
|
|
+ s_sql = f'select spider_link from crawler_task where source={source}'
|
|
|
+ result = MysqlHelper.get_values(s_sql)
|
|
|
+ if link in eval(result[0]):
|
|
|
+ exist_outer_info.append(link)
|
|
|
+ if exist_outer_info:
|
|
|
+ return jsonify({'code': 200, 'message': '名单重复', 'spider_link': exist_outer_info})
|
|
|
+
|
|
|
+ keys = ','.join(data.keys())
|
|
|
+ values = ','.join(['%s'] * len(data))
|
|
|
+ sql = 'insert into {table}({keys}) VALUES({values})'.format(table='crawler_task', keys=keys, values=values)
|
|
|
+ MysqlHelper.insert_values(sql, tuple(data.values()))
|
|
|
|
|
|
-
|
|
|
+ return jsonify({'code': 200, 'message': 'task create success'})
|
|
|
|
|
|
|
|
|
-@app.route("/v1/task/gettask", methods=["GET"])
|
|
|
-def getTask():
|
|
|
+@app.route("/v1/crawler/task/gettask", methods=["GET"])
|
|
|
+def getAllTask():
|
|
|
get_data = request.args.to_dict()
|
|
|
-
|
|
|
- sql = 'select task_id, task_name from crawler_task'
|
|
|
+ page = get_data.get('page', 1)
|
|
|
+ offset = get_data.get('offset', 10)
|
|
|
+ start_count = (page * offset) - offset
|
|
|
+ end_count = page * offset
|
|
|
+ sql = f"""select task_id, task_name from crawler_task limit {start_count}, {end_count}"""
|
|
|
result = MysqlHelper.get_values(sql)
|
|
|
if not result:
|
|
|
return jsonify({'return_code': '200', 'result': [], 'message': 'no data'})
|
|
@@ -55,16 +72,71 @@ def getTask():
|
|
|
task_name=task_name,
|
|
|
)
|
|
|
source_list.append(data)
|
|
|
- return jsonify({'return_code': '200', 'result': source_list})
|
|
|
+ return jsonify({'code': '200', 'result': source_list})
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@app.route("/v1/crawler/task/update", methods=["POST"])
|
|
|
+def updateTask():
|
|
|
+ task_id = request.form.get('task_id')
|
|
|
+ spider_link = request.form.get('spider_link')
|
|
|
+ print(spider_link, task_id)
|
|
|
|
|
|
+ sql = f"""UPDATE crawler_task SET spider_link='{spider_link}' where task_id = {task_id}"""
|
|
|
+ print(sql)
|
|
|
+ result = MysqlHelper.update_values(sql)
|
|
|
+ if result:
|
|
|
+ return jsonify({'code': 200, 'message': 'task update success'})
|
|
|
+ else:
|
|
|
+ return jsonify({'code': 400, 'message': 'task update faild'})
|
|
|
|
|
|
-@app.route("/v1/author/getuser", methods=["POST"])
|
|
|
+
|
|
|
+def get_user_info(source):
|
|
|
+ source_spider = {
|
|
|
+ 'xigua': xigua_user_info
|
|
|
+ }
|
|
|
+ return source_spider.get(source)
|
|
|
+
|
|
|
+
|
|
|
+@app.route("/v1/crawler/author/create", methods=["POST"])
|
|
|
def createUser():
|
|
|
- data = request.form.get('author')
|
|
|
- print(eval(data))
|
|
|
- for i in eval(data):
|
|
|
- print(i)
|
|
|
- return jsonify({'data':data})
|
|
|
+ get_media_url = 'http://videotest-internal.yishihui.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
|
|
|
+ data = request.form.get('spider_link')
|
|
|
+ source = request.form.get('source')
|
|
|
+ user_tag = request.form.get('user_tag')
|
|
|
+ for author_url in eval(data):
|
|
|
+
|
|
|
+
|
|
|
+ post_data = {
|
|
|
+
|
|
|
+
|
|
|
+ 'pwd': '',
|
|
|
+ 'nickName': '',
|
|
|
+ 'avatarUrl': '',
|
|
|
+
|
|
|
+ 'tagName': user_tag,
|
|
|
+ }
|
|
|
+ response = requests.post(url=get_media_url, params=post_data)
|
|
|
+
|
|
|
+ media_id = response.json()['data']
|
|
|
+
|
|
|
+ return jsonify({'data': data})
|
|
|
+
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- app.run(debug=True)
|
|
|
+ app.run(debug=True,port=5050)
|