PromoterInfoWebHook.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. import random
  12. import redis
  13. from flask import Flask, request, json
  14. from DouyinSpider.SpiderDouyinHeader import SpiderDouyinHeader
  15. from constant.ConfConstant import ConfConstant
  16. from spider.PromoterFansInfo import PromoterFansInfo
  17. from spider.PromoterInfoSpider import PromoterInfoSpider
  18. from spider.PromoterLiveInfoSpider import PromoterLiveInfoSpider
  19. from spider.PromoterVideoAnalysisInfo import PromoterVideoAnalysisInfo
  20. from spider.PromoterVideoAnalysisTrend import PromoterVideoAnalysisTrend
  21. from multiprocessing import Process
  22. from spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpider
  23. from utils.cookie_update import cookie_update
  24. from utils.douyin_cookie_update import douyin_cookie_update
  25. from utils.send_feishu_msg import SendFeiShuMsg
  26. app = Flask(__name__)
  27. def api_root():
  28. return 'Welcome guys'
  29. @app.route('/promoterInfo/getPromoterId', methods=['POST'])
  30. def webhook_get_promoter():
  31. r = redis.Redis(host='192.168.0.193', password='hcst@2022', port=6379, db=0)
  32. rep = json.loads(request.data)
  33. promoterId = rep["promoterId"]
  34. media_id = rep["mediaId"]
  35. if media_id == '2' or media_id is None:
  36. if r.zcard('kuaishou_shop_click_token') == 0:
  37. cookie_update.get_click_coookie_to_redis()
  38. else:
  39. random_member = r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
  40. random_item = random.choice(random_member)
  41. cookie = random_item[0].decode('utf-8')
  42. phone_num = int(random_item[1])
  43. roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
  44. if json.loads(roll).__contains__("result"):
  45. if json.loads(roll)["result"] == 100110000:
  46. r.zrem('kuaishou_shop_click_token', random_item[0])
  47. SendFeiShuMsg.send_cookie_robot_msg(
  48. "cookie 永久失效 轻更新cookie 唯一电话为{phone_num}".format(phone_num=phone_num))
  49. retry_item = cookie_update.r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
  50. print(retry_item[0][0],'-----cookie-----')
  51. retry_cookie = retry_item[0][0].decode('utf-8')
  52. cookie_update.update_cookie_handler(phone_num)
  53. rollback = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
  54. p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
  55. p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
  56. p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
  57. args=(promoterId, retry_cookie))
  58. p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
  59. args=(promoterId, retry_cookie))
  60. p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
  61. args=(promoterId, retry_cookie))
  62. p1.start()
  63. p2.start()
  64. p3.start()
  65. p4.start()
  66. p5.start()
  67. return rollback
  68. else:
  69. cookie_update.update_temporary_cookie_handler(phone_num)
  70. r.zrem('kuaishou_shop_click_token', random_item[0])
  71. retry_item = cookie_update.r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
  72. retry_cookie = retry_item[0][0].decode('utf-8')
  73. rolls = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
  74. p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
  75. p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
  76. p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
  77. args=(promoterId, retry_cookie))
  78. p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
  79. args=(promoterId, retry_cookie))
  80. p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
  81. args=(promoterId, retry_cookie))
  82. p1.start()
  83. p2.start()
  84. p3.start()
  85. p4.start()
  86. p5.start()
  87. return rolls
  88. else:
  89. p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, cookie))
  90. p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, cookie))
  91. p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander, args=(promoterId, cookie))
  92. p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
  93. args=(promoterId, cookie))
  94. p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
  95. args=(promoterId, cookie))
  96. p1.start()
  97. p2.start()
  98. p3.start()
  99. p4.start()
  100. p5.start()
  101. r.zrem('kuaishou_shop_click_token', random_item[0])
  102. return roll
  103. else:
  104. rep = json.loads(request.data)
  105. promoterId = rep["promoterId"]
  106. cookie = douyin_cookie_update.get_cookie_handler()[0]
  107. phone_num = douyin_cookie_update.get_cookie_handler()[1]
  108. roll = SpiderDouyinHeader().DouyinHandler(promoterId, cookie)
  109. if roll != 10086:
  110. return roll
  111. else:
  112. douyin_cookie_update.update_cookie_handler(phone_num)
  113. return {}
  114. @app.route('/promoterInfo/updatePromoter', methods=['POST'])
  115. def webhook_update_promoter():
  116. r = redis.Redis(host='192.168.0.193', password='hcst@2022', port=6379, db=0)
  117. rep = json.loads(request.data)
  118. promoterId = rep["promoterId"]
  119. if r.zcard('kuaishou_shop_click_token') == 0:
  120. cookie_update.get_click_coookie_to_redis()
  121. else:
  122. random_member = r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
  123. random_item = random.choice(random_member)
  124. cookie = random_item[0].decode('utf-8')
  125. ReturnPromoterInfoSpider().PromoterUpdate(promoterId, cookie)
  126. r.close()
  127. return '0'
  128. if __name__ == '__main__':
  129. app.run(port=9999, host=ConfConstant.URL, debug=True)