PromoterInfoWebHook.py 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 constant.ConfConstant import ConfConstant
  13. from spider.PromoterFansInfo import PromoterFansInfo
  14. from spider.PromoterInfoSpider import PromoterInfoSpider
  15. from spider.PromoterLiveInfoSpider import PromoterLiveInfoSpider
  16. from spider.PromoterVideoAnalysisInfo import PromoterVideoAnalysisInfo
  17. from spider.PromoterVideoAnalysisTrend import PromoterVideoAnalysisTrend
  18. from multiprocessing import Process
  19. from spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpider
  20. from utils.cookie_update import cookie_update
  21. from utils.send_feishu_msg import SendFeiShuMsg
  22. app = Flask(__name__)
  23. def api_root():
  24. return 'Welcome guys'
  25. @app.route('/promoterInfo/getPromoterId', methods=['POST'])
  26. def webhook_get_promoter():
  27. rep = json.loads(request.data)
  28. promoterId = rep["promoterId"]
  29. cookie = cookie_update.get_cookie_handler()[0]
  30. phone_num = cookie_update.get_cookie_handler()[1]
  31. roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
  32. if json.loads(roll).__contains__("result"):
  33. if json.loads(roll)["result"] == 100110000:
  34. SendFeiShuMsg.send_cookie_robot_msg("cookie 永久失效 轻更新cookie 唯一电话为{phone_num}".format(phone_num=phone_num))
  35. cookie_update.update_cookie_handler(phone_num)
  36. retry_cookie = cookie_update.get_cookie_handler()[0]
  37. rollback = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
  38. p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
  39. p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
  40. p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander, args=(promoterId, retry_cookie))
  41. p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
  42. args=(promoterId, retry_cookie))
  43. p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
  44. args=(promoterId, retry_cookie))
  45. p1.start()
  46. p2.start()
  47. p3.start()
  48. p4.start()
  49. p5.start()
  50. return rollback
  51. else:
  52. SendFeiShuMsg.send_cookie_robot_msg("cookie 临时失效 唯一电话为{phone_num},临时失效code{code}".format(phone_num=phone_num,code=json.loads(roll)["result"]))
  53. cookie_update.update_temporary_cookie_handler(phone_num)
  54. retry_cookie = cookie_update.get_cookie_handler()[0]
  55. rolls = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
  56. p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
  57. p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
  58. p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander, args=(promoterId, retry_cookie))
  59. p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
  60. args=(promoterId, retry_cookie))
  61. p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
  62. args=(promoterId, retry_cookie))
  63. p1.start()
  64. p2.start()
  65. p3.start()
  66. p4.start()
  67. p5.start()
  68. return rolls
  69. else:
  70. p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, cookie))
  71. p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, cookie))
  72. p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander, args=(promoterId, cookie))
  73. p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler, args=(promoterId, cookie))
  74. p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler, args=(promoterId, cookie))
  75. p1.start()
  76. p2.start()
  77. p3.start()
  78. p4.start()
  79. p5.start()
  80. return roll
  81. if __name__ == '__main__':
  82. app.run(port=9999, host=ConfConstant.URL, debug=True)