123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- """
- Author renyupeng
- coding=utf-8
- @Time : 2023/2/9 5:07 下午
- @Site :
- @File : PromoterInfoWebHook.py
- @Software: PyCharm
- @contact: renyupeng@c-top.com.cn
- @Tel 1501435553
- """
- import random
- import redis
- from flask import Flask, request, json
- from DouyinSpider.SpiderDouyinHeader import SpiderDouyinHeader
- from constant.ConfConstant import ConfConstant
- from spider.PromoterFansInfo import PromoterFansInfo
- from spider.PromoterInfoSpider import PromoterInfoSpider
- from spider.PromoterLiveInfoSpider import PromoterLiveInfoSpider
- from spider.PromoterVideoAnalysisInfo import PromoterVideoAnalysisInfo
- from spider.PromoterVideoAnalysisTrend import PromoterVideoAnalysisTrend
- from multiprocessing import Process
- from spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpider
- from utils.cookie_update import cookie_update
- from utils.douyin_cookie_update import douyin_cookie_update
- from utils.send_feishu_msg import SendFeiShuMsg
- app = Flask(__name__)
- def api_root():
- return 'Welcome guys'
- @app.route('/promoterInfo/getPromoterId', methods=['POST'])
- def webhook_get_promoter():
- r = redis.Redis(host='192.168.0.99', password='', port=6379, db=0)
- rep = json.loads(request.data)
- promoterId = rep["promoterId"]
- media_id = rep["mediaId"]
- if media_id == '2' or media_id is None:
- if r.zcard('kuaishou_shop_click_token') == 0:
- cookie_update.get_click_coookie_to_redis()
- else:
- random_member = r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
- random_item = random.choice(random_member)
- cookie = random_item[0].decode('utf-8')
- phone_num = int(random_item[1])
- roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
- print(roll,'-----111-----{promoterId}'.format(promoterId=promoterId))
- if json.loads(roll).__contains__("result"):
- if json.loads(roll)["result"] == 109:
- r.zrem('kuaishou_shop_click_token', random_item[0])
- SendFeiShuMsg.send_cookie_robot_msg(
- "cookie 永久失效 轻更新cookie 唯一电话为{phone_num}".format(phone_num=phone_num))
- retry_item = cookie_update.r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
- print(retry_item[0][0],'-----cookie-----')
- retry_cookie = retry_item[0][0].decode('utf-8')
- cookie_update.update_cookie_handler(phone_num)
- rollback = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
- p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
- p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
- p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
- args=(promoterId, retry_cookie))
- p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
- args=(promoterId, retry_cookie))
- p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
- args=(promoterId, retry_cookie))
- p1.start()
- p2.start()
- p3.start()
- p4.start()
- p5.start()
- print(rollback,'--222---{promoterId}'.format(promoterId=promoterId))
- return rollback
- else:
- cookie_update.update_temporary_cookie_handler(phone_num)
- r.zrem('kuaishou_shop_click_token', random_item[0])
- retry_item = cookie_update.r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
- retry_cookie = retry_item[0][0].decode('utf-8')
- rolls = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
- p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
- p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
- p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
- args=(promoterId, retry_cookie))
- p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
- args=(promoterId, retry_cookie))
- p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
- args=(promoterId, retry_cookie))
- p1.start()
- p2.start()
- p3.start()
- p4.start()
- p5.start()
- print(rolls, '-------333-roll3---------{promoterId}'.format(promoterId=promoterId))
- return rolls
- else:
- p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, cookie))
- p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, cookie))
- p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander, args=(promoterId, cookie))
- p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
- args=(promoterId, cookie))
- p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
- args=(promoterId, cookie))
- p1.start()
- p2.start()
- p3.start()
- p4.start()
- p5.start()
- r.zrem('kuaishou_shop_click_token', random_item[0])
- print(roll, '--------444---roll1---------{promoterId}'.format(promoterId=promoterId))
- return roll
- else:
- rep = json.loads(request.data)
- promoterId = rep["promoterId"]
- cookie = douyin_cookie_update.get_cookie_handler()[0]
- phone_num = douyin_cookie_update.get_cookie_handler()[1]
- roll = SpiderDouyinHeader().DouyinHandler(promoterId, cookie)
- if roll != 10086:
- print(roll, '--------roll2---------{promoterId}'.format(promoterId=promoterId))
- return roll
- else:
- douyin_cookie_update.update_cookie_handler(phone_num)
- return {}
- @app.route('/promoterInfo/updatePromoter', methods=['POST'])
- def webhook_update_promoter():
- r = redis.Redis(host='192.168.0.99', password='', port=6379, db=0)
- rep = json.loads(request.data)
- promoterId = rep["promoterId"]
- if r.zcard('kuaishou_shop_click_token') == 0:
- cookie_update.get_click_coookie_to_redis()
- else:
- random_member = r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
- random_item = random.choice(random_member)
- cookie = random_item[0].decode('utf-8')
- ReturnPromoterInfoSpider().PromoterUpdate(promoterId, cookie)
- r.close()
- return '0'
- if __name__ == '__main__':
- app.run(port=9999, host=ConfConstant.URL, debug=True)
|