webHook.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import datetime
  2. import logging
  3. import traceback
  4. import requests
  5. from flask import json # To read json data
  6. from flask import request # To receive headers
  7. from flask import Flask # To be able to start the application
  8. from ConfConstant import ConfConstant
  9. from report.AccountReport import AccountReport
  10. from Apietl.bytedance_etl.report import AdvertiserReport
  11. app = Flask(__name__)
  12. @app.route('/')
  13. def api_root():
  14. return 'Welcome guys'
  15. @app.route('/webhook/account_report', methods=['POST'])
  16. def api_webhook_messages():
  17. print(json.loads(request.data))
  18. my_info = json.loads(request.data)
  19. account_id = my_info["account_id"]
  20. start_date = my_info["start_date"]
  21. end_date = my_info["end_date"]
  22. date_type = my_info["date_type"]
  23. AccountReport().handler(date_type, account_id, start_date, end_date)
  24. return '200'
  25. @app.route('/webhook/bytedance_account_report', methods=['POST'])
  26. def api_webhook_bytedance_messages():
  27. print(json.loads(request.data))
  28. my_info = json.loads(request.data)
  29. account_id = my_info["adveriser_id"]
  30. start_date = my_info["start_date"]
  31. end_date = my_info["end_date"]
  32. date_type = my_info["date_type"]
  33. AdvertiserReport().handler(date_type, account_id, start_date, end_date)
  34. return '200'
  35. if __name__ == '__main__':
  36. app.run(port=8765, host=ConfConstant.URL, debug=True)