SpiderWeekPromoterInfo.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2023/9/11 下午4:19
  4. # @Site :
  5. # @File : SpiderWeekPromoterInfo.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import json
  10. import time
  11. import random
  12. from multiprocessing import Process
  13. import redis
  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 spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpider
  20. from utils.cookie_update import cookie_update
  21. from utils.mysql_utils_pro import MysqlProUtils
  22. from utils.send_feishu_msg import SendFeiShuMsg
  23. class SpiderWeekPromoterInfo:
  24. def __init__(self):
  25. self.r = redis.Redis(host='192.168.0.193', password='hcst@2022', port=6379, db=0)
  26. self.conn = MysqlProUtils()
  27. def get_promoter(self, promoterId):
  28. if self.r.zcard('kuaishou_shop_token') == 0:
  29. cookie_update.get_coookie_to_redis()
  30. else:
  31. random_member = cookie_update.r.zrange('kuaishou_shop_token', 0, -1, withscores=True)
  32. random_item = random.choice(random_member)
  33. cookie = random_item[0].decode('utf-8')
  34. phone_num = int(random_item[1])
  35. roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
  36. if json.loads(roll).__contains__("result"):
  37. if json.loads(roll)["result"] == 100110000:
  38. cookie_update.r.zrem('kuaishou_shop_token', random_item[0])
  39. SendFeiShuMsg.send_cookie_robot_msg(
  40. "cookie 永久失效 轻更新cookie 唯一电话为{phone_num}".format(phone_num=phone_num))
  41. retry_item = cookie_update.r.zrange('kuaishou_shop_token', 0, -1, withscores=True)
  42. retry_cookie = retry_item[0].decode('utf-8')
  43. cookie_update.update_cookie_handler(phone_num)
  44. # PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
  45. # PromoterFansInfo().PromoterFansInfoHandler(promoterId, retry_cookie)
  46. # PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId, retry_cookie)
  47. # PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId, retry_cookie)
  48. # PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId, retry_cookie)
  49. else:
  50. SendFeiShuMsg.send_cookie_robot_msg(
  51. "cookie 临时失效 唯一电话为{phone_num},临时失效code{code}".format(phone_num=phone_num,
  52. code=json.loads(roll)["result"]))
  53. cookie_update.update_temporary_cookie_handler(phone_num)
  54. cookie_update.r.zrem('kuaishou_shop_token', random_item[0])
  55. retry_item = cookie_update.r.zrange('kuaishou_shop_token', 0, -1, withscores=True)
  56. retry_cookie = retry_item[0].decode('utf-8')
  57. # PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
  58. # PromoterFansInfo().PromoterFansInfoHandler(promoterId, retry_cookie)
  59. # PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId, retry_cookie)
  60. # PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId, retry_cookie)
  61. # PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId, retry_cookie)
  62. else:
  63. # PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
  64. # PromoterFansInfo().PromoterFansInfoHandler(promoterId, cookie)
  65. # PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId, cookie)
  66. # PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId, cookie)
  67. # PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId, cookie)
  68. roll = json.loads(roll)
  69. fanNum = roll["fanNum"]
  70. totalSale = roll["totalSale"]
  71. avgVideoSales = roll["avgVideoSales"]
  72. videoSales = roll["videoSales"]
  73. sql = """ replace into ruixuan.promoter_sales_info(promoter_id, total_sale, fans_number, avg_video_sales, video_sales) values (
  74. {promoterId},'{totalSale}',{fanNum},'{avgVideoSales}','{videoSales}'
  75. ) """.format(totalSale=totalSale, fanNum=fanNum, avgVideoSales=avgVideoSales, videoSales=videoSales,
  76. promoterId=promoterId)
  77. MysqlProUtils().Operate(sql=sql)
  78. cookie_update.r.zrem('kuaishou_shop_token', random_item[0])
  79. def get_promoter_info(self):
  80. sql = """
  81. select promoter_id from ruixuan.promoter_info
  82. """
  83. promoter_result = self.conn.QueryAll(sql)
  84. for promoter in promoter_result:
  85. promoter_id = int(promoter[0].decode('utf-8'))
  86. self.get_promoter(promoter_id)
  87. time.sleep(2)
  88. if __name__ == '__main__':
  89. SpiderWeekPromoterInfo().get_promoter_info()