新增任务执行状态记录接口
This commit is contained in:
parent
f2f5e0e3d5
commit
be27217357
37
app.py
37
app.py
|
@ -65,7 +65,7 @@ def add_h5_user():
|
||||||
success = False
|
success = False
|
||||||
while not success and retry_count < max_retries:
|
while not success and retry_count < max_retries:
|
||||||
try:
|
try:
|
||||||
account_id = uuid.uuid4().hex
|
account_id = uuid.uuid4().int
|
||||||
sql_str = """INSERT INTO account_h5_info
|
sql_str = """INSERT INTO account_h5_info
|
||||||
(account_id, keep_rate, task_total,
|
(account_id, keep_rate, task_total,
|
||||||
account_name, countries, link_url)
|
account_name, countries, link_url)
|
||||||
|
@ -130,9 +130,9 @@ def download_file():
|
||||||
|
|
||||||
@app.route('/upload_browser_info', methods=['POST'])
|
@app.route('/upload_browser_info', methods=['POST'])
|
||||||
def upload_browser_info():
|
def upload_browser_info():
|
||||||
try:
|
|
||||||
params = json.loads(request.data)
|
params = json.loads(request.data)
|
||||||
visitor_id = params["fingerprint"]['visitorId']
|
visitor_id = params["fingerprint"]['visitorId']
|
||||||
|
try:
|
||||||
app.logger.info("接口:upload_browser_info 被调用,传入参数为:{}".format(str(visitor_id)))
|
app.logger.info("接口:upload_browser_info 被调用,传入参数为:{}".format(str(visitor_id)))
|
||||||
# 对数据进行保存
|
# 对数据进行保存
|
||||||
sql_str = "insert into task_h5_browser_info(visitor_id,browser_info) values(%s,%s)"
|
sql_str = "insert into task_h5_browser_info(visitor_id,browser_info) values(%s,%s)"
|
||||||
|
@ -140,6 +140,8 @@ def upload_browser_info():
|
||||||
return jsonify({'status': 'ok'})
|
return jsonify({'status': 'ok'})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "PRIMARY" in str(e):
|
if "PRIMARY" in str(e):
|
||||||
|
sql_str = "UPDATE task_h5_browser_info SET browser_info = %s,update_time=%s WHERE visitor_id = %s "
|
||||||
|
db.execute_update(sql_str, (json.dumps(params), datetime.now(), visitor_id))
|
||||||
return jsonify({'status': 'ok'})
|
return jsonify({'status': 'ok'})
|
||||||
app.logger.info("浏览器信息保存失败,失败原因:{}".format(str(e)))
|
app.logger.info("浏览器信息保存失败,失败原因:{}".format(str(e)))
|
||||||
return jsonify({'status': 'error', 'msg': str(e)})
|
return jsonify({'status': 'error', 'msg': str(e)})
|
||||||
|
@ -166,12 +168,25 @@ def get_account_id():
|
||||||
return jsonify({'status': "error", "message": "<UNK>"})
|
return jsonify({'status': "error", "message": "<UNK>"})
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/upload_task_status', methods=['GET'])
|
||||||
|
def upload_task_status():
|
||||||
|
try:
|
||||||
|
sql_str = "UPDATE task_execute_status SET task_status = %s, WHERE account_id = %s and task_id=%s"
|
||||||
|
db.execute_update(sql_str, (request.args.get("task_status"), request.args.get('account_id'), request.args.get('task_id')))
|
||||||
|
return jsonify({'status': 'ok'})
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.info("<UNK>{}".format(str(e)))
|
||||||
|
return jsonify({'status': "error", "message": str(e)})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/h5_issue_task', methods=['GET'])
|
@app.route('/h5_issue_task', methods=['GET'])
|
||||||
def issue_task():
|
def issue_task():
|
||||||
account_id = request.args.get('accountId')
|
account_id = request.args.get('accountId')
|
||||||
sql_str = "select account_id,keep_rate,task_total,account_name,is_active from account_h5_info where account_id=%s"
|
sql_str = "select account_id,keep_rate,task_total,account_name,is_active,countries,link_url from account_h5_info where account_id=%s and is_active=1"
|
||||||
result = db.execute_query(sql_str, (account_id,))
|
result = db.execute_query(sql_str, (account_id,))
|
||||||
if result:
|
if result:
|
||||||
|
countries = result[0][-2]
|
||||||
|
link_url = result[0][-1]
|
||||||
task_total = int(result[0][2])
|
task_total = int(result[0][2])
|
||||||
app.logger.info("账户:{}需要执行新增任务总数为:{}".format(account_id, task_total))
|
app.logger.info("账户:{}需要执行新增任务总数为:{}".format(account_id, task_total))
|
||||||
now_date = datetime.now().strftime("%Y-%m-%d")
|
now_date = datetime.now().strftime("%Y-%m-%d")
|
||||||
|
@ -198,7 +213,12 @@ def issue_task():
|
||||||
sql_str = "select browser_info from task_h5_browser_info ORDER BY RAND() LIMIT 1"
|
sql_str = "select browser_info from task_h5_browser_info ORDER BY RAND() LIMIT 1"
|
||||||
result = db.execute_query(sql_str)
|
result = db.execute_query(sql_str)
|
||||||
if result:
|
if result:
|
||||||
return jsonify(json.loads(result[0][0]))
|
task_id = uuid.uuid4().hex
|
||||||
|
# 将任务,记录到对应表中
|
||||||
|
sql_str = "insert into task_execute_status(account_id,task_id,task_status) values(%s,%s)"
|
||||||
|
db.execute_single(sql_str, (account_id, task_id))
|
||||||
|
return jsonify({"link_url": link_url, "task_id": task_id,
|
||||||
|
"countries": countries, "file_name": f"{account_id}/main.js", "browser_info": json.loads(result[0][0])})
|
||||||
else:
|
else:
|
||||||
app.logger.info("未获取到账户:{} 相关配置信息".format(account_id))
|
app.logger.info("未获取到账户:{} 相关配置信息".format(account_id))
|
||||||
return jsonify({'status': 'error', 'msg': '传入账号错误'})
|
return jsonify({'status': 'error', 'msg': '传入账号错误'})
|
||||||
|
@ -224,19 +244,10 @@ def upload_file():
|
||||||
return jsonify({'message': 'File uploaded successfully', 'path': file_path})
|
return jsonify({'message': 'File uploaded successfully', 'path': file_path})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['get'])
|
@app.route('/', methods=['get'])
|
||||||
def test_post():
|
def test_post():
|
||||||
return jsonify({"key": "value"})
|
return jsonify({"key": "value"})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=5000)
|
app.run(host='0.0.0.0', port=5000)
|
||||||
|
|
Loading…
Reference in New Issue