PromoterInfoWebHook.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. """
  2. Author renyupeng
  3. coding=utf-8
  4. @Time : 2023/2/9 5:07 下午
  5. @Site :
  6. @File : PromoterInfoWebHook.py
  7. @Software: PyCharm
  8. @contact: renyupeng@c-top.com.cn
  9. @Tel 1501435553
  10. """
  11. from flask import Flask, request, json
  12. from DouyinSpider.SpiderDouyinHeader import SpiderDouyinHeader
  13. from constant.ConfConstant import ConfConstant
  14. from spider.PromoterFansInfo import PromoterFansInfo
  15. from spider.PromoterInfoSpider import PromoterInfoSpider
  16. from spider.PromoterLiveInfoSpider import PromoterLiveInfoSpider
  17. from spider.PromoterVideoAnalysisInfo import PromoterVideoAnalysisInfo
  18. from spider.PromoterVideoAnalysisTrend import PromoterVideoAnalysisTrend
  19. from multiprocessing import Process
  20. from spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpider
  21. from utils.cookie_update import cookie_update
  22. from utils.douyin_cookie_update import douyin_cookie_update
  23. from utils.send_feishu_msg import SendFeiShuMsg
  24. app = Flask(__name__)
  25. def api_root():
  26. return 'Welcome guys'
  27. @app.route('/promoterInfo/getPromoterId', methods=['POST'])
  28. def webhook_get_promoter():
  29. rep = json.loads(request.data)
  30. promoterId = rep["promoterId"]
  31. media_id = rep["mediaId"]
  32. if media_id == '2' or media_id is None:
  33. cookie = cookie_update.get_cookie_handler()[0]
  34. phone_num = cookie_update.get_cookie_handler()[1]
  35. roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
  36. if json.loads(roll).__contains__("result"):
  37. if json.loads(roll)["result"] == 100110000:
  38. SendFeiShuMsg.send_cookie_robot_msg(
  39. "cookie 永久失效 轻更新cookie 唯一电话为{phone_num}".format(phone_num=phone_num))
  40. cookie_update.update_cookie_handler(phone_num)
  41. retry_cookie = cookie_update.get_cookie_handler()[0]
  42. rollback = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
  43. p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
  44. p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
  45. p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
  46. args=(promoterId, retry_cookie))
  47. p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
  48. args=(promoterId, retry_cookie))
  49. p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
  50. args=(promoterId, retry_cookie))
  51. p1.start()
  52. p2.start()
  53. p3.start()
  54. p4.start()
  55. p5.start()
  56. return rollback
  57. else:
  58. SendFeiShuMsg.send_cookie_robot_msg(
  59. "cookie 临时失效 唯一电话为{phone_num},临时失效code{code}".format(phone_num=phone_num,
  60. code=json.loads(roll)["result"]))
  61. cookie_update.update_temporary_cookie_handler(phone_num)
  62. retry_cookie = cookie_update.get_cookie_handler()[0]
  63. rolls = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
  64. p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
  65. p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
  66. p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
  67. args=(promoterId, retry_cookie))
  68. p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
  69. args=(promoterId, retry_cookie))
  70. p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
  71. args=(promoterId, retry_cookie))
  72. p1.start()
  73. p2.start()
  74. p3.start()
  75. p4.start()
  76. p5.start()
  77. return rolls
  78. else:
  79. p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, cookie))
  80. p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, cookie))
  81. p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander, args=(promoterId, cookie))
  82. p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler, args=(promoterId, cookie))
  83. p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
  84. args=(promoterId, cookie))
  85. p1.start()
  86. p2.start()
  87. p3.start()
  88. p4.start()
  89. p5.start()
  90. return roll
  91. else:
  92. rep = json.loads(request.data)
  93. promoterId = rep["promoterId"]
  94. cookie = douyin_cookie_update.get_cookie_handler()[0]
  95. phone_num = douyin_cookie_update.get_cookie_handler()[1]
  96. roll = SpiderDouyinHeader().DouyinHandler(promoterId, cookie)
  97. if roll != 10086:
  98. return roll
  99. else:
  100. douyin_cookie_update.update_cookie_handler(phone_num)
  101. return {}
  102. @app.route('/promoterInfo/updatePromoter', methods=['POST'])
  103. def webhook_update_promoter():
  104. rep = json.loads(request.data)
  105. promoterId = rep["promoterId"]
  106. cookie = cookie_update.get_cookie_handler()[0]
  107. ReturnPromoterInfoSpider().PromoterUpdate(promoterId, cookie)
  108. return '0'
  109. if __name__ == '__main__':
  110. app.run(port=9999, host=ConfConstant.URL, debug=True)