webHook.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import datetime
  2. import logging
  3. import os
  4. import traceback
  5. import requests
  6. from flask import json, jsonify # To read json data
  7. from flask import request # To receive headers
  8. from flask import Flask # To be able to start the application
  9. from werkzeug.utils import secure_filename
  10. from Apietl.constant.ConfConstant import ConfConstant
  11. from Apietl.kwai_etl.report.AccountReport import AccountReport
  12. from Apietl.bytedance_etl.report.AdvertiserReport import AdvertiserReport
  13. from Apietl.utlis.EtlFirstDeliveryValidMaterials import EtlFirstDeliveryValidMaterials
  14. from Apietl.utlis.UpLoadFile import UpLoadFile
  15. app = Flask(__name__)
  16. @app.route('/')
  17. def api_root():
  18. return 'Welcome guys'
  19. @app.route('/webhook/account_report', methods=['POST'])
  20. def api_webhook_messages():
  21. print(json.loads(request.data))
  22. my_info = json.loads(request.data)
  23. account_id = my_info["account_id"]
  24. start_date = my_info["start_date"]
  25. end_date = my_info["end_date"]
  26. date_type = my_info["date_type"]
  27. AccountReport().handler(date_type, account_id, start_date, end_date)
  28. return '200'
  29. @app.route('/webhook/bytedance_account_report', methods=['POST'])
  30. def api_webhook_bytedance_messages():
  31. print(json.loads(request.data))
  32. my_info = json.loads(request.data)
  33. account_id = my_info["advertiser_id"]
  34. start_date = my_info["start_date"]
  35. end_date = my_info["end_date"]
  36. date_type = my_info["date_type"]
  37. AdvertiserReport().handler(date_type, account_id, start_date, end_date)
  38. return '200'
  39. # @app.route('/webhook/get_file', methods=['POST'])
  40. # def api_webhook_get_file():
  41. # payload = {}
  42. # headers = {
  43. # 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
  44. # 'Accept': '*/*',
  45. # 'Host': 'api.tjyourong.com.cn',
  46. # 'Connection': 'keep-alive'
  47. # }
  48. #
  49. # if 'file' not in request.files:
  50. # url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')
  51. # response = requests.request("GET", url, headers=headers, data=payload)
  52. # print(response.text, 'error1')
  53. # return '200'
  54. # file = request.files['file']
  55. # if file.filename == '':
  56. # url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')
  57. # response = requests.request("GET", url, headers=headers, data=payload)
  58. # print(response.text, 'error2')
  59. # return '200'
  60. # try:
  61. # file.save('/home/excel/' + 'upload.csv')
  62. # status = UpLoadFile.uploadFile('upload.csv')
  63. # if status == 0:
  64. # url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='success')
  65. # requests.request("GET", url, headers=headers, data=payload)
  66. # else:
  67. # url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')
  68. # requests.request("GET", url, headers=headers, data=payload)
  69. # material_status = EtlFirstDeliveryValidMaterials().handler()
  70. # if material_status == 0:
  71. # url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='success')
  72. # requests.request("GET", url, headers=headers, data=payload)
  73. # else:
  74. # url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')
  75. # requests.request("GET", url, headers=headers, data=payload)
  76. # os.remove('/data/excel/' + 'upload.csv')
  77. # return '200'
  78. # except Exception as e:
  79. # url = "http://api.tjyourong.com.cn/jeecg-boot/first/delivery/excelCallBack?msg={msg}".format(msg='error')
  80. # response = requests.request("GET", url, headers=headers, data=payload)
  81. # print(response.text, 'error3')
  82. # return '200'
  83. if __name__ == '__main__':
  84. app.run(port=8765, host=ConfConstant.URL, debug=True)