| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 | import datetimeimport loggingimport osimport tracebackimport requestsfrom flask import json, jsonify  # To read json datafrom flask import request  # To receive headersfrom flask import Flask  # To be able to start the applicationfrom werkzeug.utils import secure_filenamefrom Apietl.constant.ConfConstant import ConfConstantfrom Apietl.kwai_etl.report.AccountReport import AccountReportfrom Apietl.bytedance_etl.report.AdvertiserReport import AdvertiserReportfrom Apietl.utlis.EtlFirstDeliveryValidMaterials import EtlFirstDeliveryValidMaterialsfrom Apietl.utlis.UpLoadFile import UpLoadFileapp = Flask(__name__)@app.route('/')def api_root():    return 'Welcome guys'@app.route('/webhook/account_report', methods=['POST'])def api_webhook_messages():    print(json.loads(request.data))    my_info = json.loads(request.data)    account_id = my_info["account_id"]    start_date = my_info["start_date"]    end_date = my_info["end_date"]    date_type = my_info["date_type"]    AccountReport().handler(date_type, account_id, start_date, end_date)    return '200'@app.route('/webhook/bytedance_account_report', methods=['POST'])def api_webhook_bytedance_messages():    print(json.loads(request.data))    my_info = json.loads(request.data)    account_id = my_info["advertiser_id"]    start_date = my_info["start_date"]    end_date = my_info["end_date"]    date_type = my_info["date_type"]    AdvertiserReport().handler(date_type, account_id, start_date, end_date)    return '200'# @app.route('/webhook/get_file', methods=['POST'])# def api_webhook_get_file():#     payload = {}#     headers = {#         'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',#         'Accept': '*/*',#         'Host': 'api.tjyourong.com.cn',#         'Connection': 'keep-alive'#     }##     if 'file' not in request.files:#         url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')#         response = requests.request("GET", url, headers=headers, data=payload)#         print(response.text, 'error1')#         return '200'#     file = request.files['file']#     if file.filename == '':#         url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')#         response = requests.request("GET", url, headers=headers, data=payload)#         print(response.text, 'error2')#         return '200'#     try:#         file.save('/home/excel/' + 'upload.csv')#         status = UpLoadFile.uploadFile('upload.csv')#         if status == 0:#             url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='success')#             requests.request("GET", url, headers=headers, data=payload)#         else:#             url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')#             requests.request("GET", url, headers=headers, data=payload)#         material_status = EtlFirstDeliveryValidMaterials().handler()#         if material_status == 0:#             url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='success')#             requests.request("GET", url, headers=headers, data=payload)#         else:#             url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')#             requests.request("GET", url, headers=headers, data=payload)#         os.remove('/data/excel/' + 'upload.csv')#         return '200'#     except Exception as e:#         url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')#         response = requests.request("GET", url, headers=headers, data=payload)#         print(response.text, 'error3')#         return '200'if __name__ == '__main__':    app.run(port=8765, host=ConfConstant.URL, debug=True)
 |