| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 | """Author renyupengcoding=utf-8@Time    : 2023/2/9 5:07 下午@Site    :@File    : PromoterInfoWebHook.py@Software: PyCharm@contact: renyupeng@c-top.com.cn@Tel 1501435553"""from flask import Flask, request, jsonfrom DouyinSpider.SpiderDouyinHeader import SpiderDouyinHeaderfrom constant.ConfConstant import ConfConstantfrom spider.PromoterFansInfo import PromoterFansInfofrom spider.PromoterInfoSpider import PromoterInfoSpiderfrom spider.PromoterLiveInfoSpider import PromoterLiveInfoSpiderfrom spider.PromoterVideoAnalysisInfo import PromoterVideoAnalysisInfofrom spider.PromoterVideoAnalysisTrend import PromoterVideoAnalysisTrendfrom multiprocessing import Processfrom spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpiderfrom utils.cookie_update import cookie_updatefrom utils.douyin_cookie_update import douyin_cookie_updatefrom utils.send_feishu_msg import SendFeiShuMsgapp = Flask(__name__)def api_root():    return 'Welcome guys'@app.route('/promoterInfo/getPromoterId', methods=['POST'])def webhook_get_promoter():    rep = json.loads(request.data)    promoterId = rep["promoterId"]    media_id = rep["mediaId"]    if media_id == 2 or media_id is None:        cookie = cookie_update.get_cookie_handler()[0]        phone_num = cookie_update.get_cookie_handler()[1]        roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)        if json.loads(roll).__contains__("result"):            if json.loads(roll)["result"] == 100110000:                SendFeiShuMsg.send_cookie_robot_msg(                    "cookie 永久失效 轻更新cookie 唯一电话为{phone_num}".format(phone_num=phone_num))                cookie_update.update_cookie_handler(phone_num)                retry_cookie = cookie_update.get_cookie_handler()[0]                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()                return rollback            else:                SendFeiShuMsg.send_cookie_robot_msg(                    "cookie 临时失效 唯一电话为{phone_num},临时失效code{code}".format(phone_num=phone_num,                                                                         code=json.loads(roll)["result"]))                cookie_update.update_temporary_cookie_handler(phone_num)                retry_cookie = cookie_update.get_cookie_handler()[0]                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()                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()            return roll    else:        rep = json.loads(request.data)        promoterId = rep["promoterId"]        cookie = douyin_cookie_update.get_cookie_handler()[0]        roll = SpiderDouyinHeader().DouyinHandler(promoterId, cookie)        return roll@app.route('/promoterInfo/updatePromoter', methods=['POST'])def webhook_update_promoter():    rep = json.loads(request.data)    promoterId = rep["promoterId"]    cookie = cookie_update.get_cookie_handler()[0]    ReturnPromoterInfoSpider().PromoterUpdate(promoterId, cookie)    return '0'if __name__ == '__main__':    app.run(port=9999, host=ConfConstant.URL, debug=True)
 |