更新 app.py
This commit is contained in:
parent
b4bd2ad13f
commit
22de3cf7a5
132
app.py
132
app.py
|
@ -201,31 +201,7 @@ def upload_file():
|
||||||
return jsonify({'message': 'File uploaded successfully', 'path': file_path})
|
return jsonify({'message': 'File uploaded successfully', 'path': file_path})
|
||||||
|
|
||||||
|
|
||||||
# bigo 项目接口
|
|
||||||
|
|
||||||
def get_device_info(day_date, percent, android_id, i):
|
|
||||||
# 1. 计算总记录数
|
|
||||||
sql_str = "select count(*) from device_info where save_date=%s and android_id=%s and is_use=%s ;"
|
|
||||||
result = db.execute_query(sql_str, (day_date, android_id, i))
|
|
||||||
total_count = result[0][0]
|
|
||||||
app.logger.info(("日期:{},总共有 {} 条数据".format(day_date, total_count)))
|
|
||||||
need_deal_count = math.ceil(total_count * percent)
|
|
||||||
app.logger.info("日期:{} ,需要处理 {} 条数据".format(day_date, need_deal_count))
|
|
||||||
if need_deal_count == 0:
|
|
||||||
return []
|
|
||||||
# 计算已经处理的数量
|
|
||||||
sql_str = "select count(*) from device_info where save_date=%s and is_use=%s and android_id=%s ;"
|
|
||||||
result = db.execute_query(sql_str, (day_date, i + 1, android_id))
|
|
||||||
have_deal_count = result[0][0]
|
|
||||||
app.logger.info("日期:{} ,已经处理的数据有:{}条".format(day_date, have_deal_count))
|
|
||||||
if have_deal_count >= need_deal_count:
|
|
||||||
return []
|
|
||||||
# 准备需要处理的数据
|
|
||||||
limit_count = need_deal_count - have_deal_count
|
|
||||||
app.logger.info("日期:{} 还剩{}多少条数据需要处理".format(day_date, limit_count))
|
|
||||||
sql_str = "select id,android_id,device_info,package_name from device_info where save_date=%s and is_use=%s and android_id=%s limit %s;"
|
|
||||||
result = db.execute_query(sql_str, (day_date, i, android_id, limit_count))
|
|
||||||
return result[0]
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['get'])
|
@app.route('/', methods=['get'])
|
||||||
|
@ -233,118 +209,10 @@ def test_post():
|
||||||
return jsonify({"key": "value"})
|
return jsonify({"key": "value"})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/device_info_upload', methods=['POST'])
|
|
||||||
def device_info_upload():
|
|
||||||
try:
|
|
||||||
params = request.get_json()
|
|
||||||
app.logger.info("接口:device_info_upload 被调用,传入参数为:{}".format(str(params)))
|
|
||||||
if not params:
|
|
||||||
return jsonify({})
|
|
||||||
android_id = request.args.get('id')
|
|
||||||
device_ip = request.args.get('deviceIp')
|
|
||||||
# 留存需要修改
|
|
||||||
if android_id == "FyZqWrStUvOpKlMn":
|
|
||||||
task_id = request.args.get('taskId')
|
|
||||||
package_name = request.args.get('packageName')
|
|
||||||
if package_name:
|
|
||||||
app.logger.info("传入参数:android_id为{},package_name 为:{}".format(android_id, package_name))
|
|
||||||
app.logger.info("传入参数:android_id为{},task_id为:{}".format(android_id, task_id))
|
|
||||||
try:
|
|
||||||
sql_str = "INSERT INTO device_info(android_id, device_info,task_id,package_name,device_ip) VALUES (%s, %s,%s,%s,%s)"
|
|
||||||
db.execute_single(sql_str, (android_id, json.dumps(params), task_id, package_name, device_ip))
|
|
||||||
app.logger.info("android_id:{} 数据写入成功".format(str(android_id)))
|
|
||||||
return {"message": "android_id为:{} 的设备信息保存成功".format(android_id)}
|
|
||||||
except Exception as e:
|
|
||||||
app.logger.info({"message": "android_id为:{} 的设备信息保存失败,失败原因为:{}".format(str(android_id), str(e))})
|
|
||||||
else:
|
|
||||||
return jsonify({"status": "error", "msg": "android_id:{} 传入安装包名为{} ".format(android_id, package_name)})
|
|
||||||
return jsonify({})
|
|
||||||
except Exception as e:
|
|
||||||
app.logger.info({"message": "{}".format(str(e))})
|
|
||||||
return jsonify({})
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/device_info_download', methods=['GET'])
|
|
||||||
def device_info_download():
|
|
||||||
android_id = request.args.get('androidId')
|
|
||||||
app.logger.info("接口:device_info_download 被调用,传入参数为:{}".format(str(android_id)))
|
|
||||||
try:
|
|
||||||
percent_list = [0.5, 0.3, 0.18, 0.11, 0.09, 0.06, 0.04]
|
|
||||||
for i in range(len(percent_list)):
|
|
||||||
day = (datetime.now() - timedelta(days=i + 1)).strftime('%Y-%m-%d')
|
|
||||||
result = get_device_info(day, percent_list[i], android_id=android_id, i=i)
|
|
||||||
if result:
|
|
||||||
sql_str = "UPDATE device_info SET is_use = %s WHERE id = %s"
|
|
||||||
db.execute_update(sql_str, (i + 1, result[0]))
|
|
||||||
param = json.loads(result[-2])
|
|
||||||
param["package_name"] = result[-1]
|
|
||||||
param["file_name"] = f"{result[1]}_{result[-1]}.zip"
|
|
||||||
return jsonify(json.dumps(param))
|
|
||||||
return jsonify({})
|
|
||||||
except Exception as e:
|
|
||||||
app.logger.info("获取设备:{} 的信息失败,失败原因为:{}".format(str(android_id), str(e)))
|
|
||||||
return jsonify({})
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/count_click', methods=['GET'])
|
|
||||||
def count_click_times():
|
|
||||||
click_id = request.args.get('ClickAd')
|
|
||||||
app.logger.info("接口:{}被调用,传入参数click_id为:{}".format(click_id, str(datetime.now())))
|
|
||||||
click_date = datetime.today().strftime('%Y%m%d%H')
|
|
||||||
try:
|
|
||||||
sql_str = "insert into count_click_times(click_id,click_date) values (%s, %s)"
|
|
||||||
db.execute_single(sql_str, (click_id, click_date))
|
|
||||||
return jsonify({"message": "click_id:{}已记录".format(click_id)})
|
|
||||||
except Exception as e:
|
|
||||||
app.logger.info({"message": "{}".format(str(e))})
|
|
||||||
return jsonify({"message": "click_id:{},数据记录失败,失败原因{}".format(click_id, str(e))}), 403
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/download_code_file', methods=['GET'])
|
|
||||||
def download_code_file():
|
|
||||||
file_name = request.args.get('file_name')
|
|
||||||
app.logger.info("download_code_file 接口被调用,开始下载文件:{}".format(file_name))
|
|
||||||
path = os.path.join(os.getcwd(), "file")
|
|
||||||
file_path = os.path.join(path, f"{file_name}")
|
|
||||||
if not os.path.exists(file_path):
|
|
||||||
app.logger.info("该文件:{},不存在".format(file_name))
|
|
||||||
return jsonify({})
|
|
||||||
else:
|
|
||||||
return send_file(file_path, as_attachment=True)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/upload_package', methods=['POST'])
|
|
||||||
def upload_package():
|
|
||||||
app.logger.info("upload_package 接口已被调用")
|
|
||||||
file = request.files['file']
|
|
||||||
file_name = file.filename
|
|
||||||
app.logger.info("upload_package 接口被调用,开始查询该文件是否存在:{}".format(file_name))
|
|
||||||
path = os.path.join(os.getcwd(), f"file")
|
|
||||||
if not os.path.exists(path):
|
|
||||||
os.makedirs(path)
|
|
||||||
file_path = os.path.join(path, f"{file_name}")
|
|
||||||
# 需要对数据进行存储
|
|
||||||
if os.path.exists(file_path):
|
|
||||||
app.logger.info("该 package:{},当天上传过,需要先删除再保存".format(file_name))
|
|
||||||
os.remove(file_path)
|
|
||||||
|
|
||||||
file.save(file_path)
|
|
||||||
app.logger.info("package:{}已保持".format(file_name))
|
|
||||||
return jsonify({'message': 'File uploaded successfully', 'path': file_path})
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/download_package', methods=['GET'])
|
|
||||||
def download_package():
|
|
||||||
app.logger.info("接口被调用")
|
|
||||||
file_name = request.args.get('file_name')
|
|
||||||
path = os.path.join(os.getcwd(), "file")
|
|
||||||
file_path = os.path.join(path, f"{file_name}")
|
|
||||||
app.logger.info(file_path)
|
|
||||||
if not os.path.exists(file_path):
|
|
||||||
app.logger.info("压缩包:{},不存在".format(file_name))
|
|
||||||
return jsonify({}), 404
|
|
||||||
else:
|
|
||||||
return send_file(file_path, as_attachment=True)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue