SpiderPromoterInfo.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2023/9/11 下午4:19
  4. # @Site :
  5. # @File : SpiderPromoterInfo.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import json
  10. import threading
  11. import time
  12. import random
  13. import redis
  14. from spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpider
  15. from utils.cookie_update import cookie_update
  16. from utils.mysql_utils_pro import MysqlProUtils
  17. class SpiderPromoterInfo:
  18. conn = MysqlProUtils()
  19. @staticmethod
  20. def get_promoter(promoterId):
  21. print(promoterId, '22222')
  22. cookie = cookie_update.get_cookie_handler()[0]
  23. roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
  24. print(roll, '------')
  25. if json.loads(roll).__contains__("result"):
  26. retry_cookie = cookie_update.get_cookie_handler()[0]
  27. roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
  28. try:
  29. roll = json.loads(roll)
  30. fanNum = roll["fanNum"]
  31. totalSale = roll["totalSale"]
  32. avgVideoSales = roll["avgVideoSales"]
  33. videoSales = roll["videoSales"]
  34. sql = """ replace into ruixuan.promoter_sales_info(promoter_id, total_sale, fans_number, avg_video_sales, video_sales) values (
  35. {promoterId},'{totalSale}',{fanNum},'{avgVideoSales}','{videoSales}'
  36. ) """.format(totalSale=totalSale, fanNum=fanNum, avgVideoSales=avgVideoSales,
  37. videoSales=videoSales,
  38. promoterId=promoterId)
  39. MysqlProUtils().Operate(sql=sql)
  40. except Exception as e:
  41. print(e)
  42. else:
  43. roll = json.loads(roll)
  44. print(roll, '--roll--', promoterId)
  45. fanNum = roll["fanNum"]
  46. totalSale = roll["totalSale"]
  47. avgVideoSales = roll["avgVideoSales"]
  48. videoSales = roll["videoSales"]
  49. sql = """ replace into ruixuan.promoter_sales_info(promoter_id, total_sale, fans_number, avg_video_sales, video_sales) values (
  50. {promoterId},'{totalSale}',{fanNum},'{avgVideoSales}','{videoSales}'
  51. ) """.format(totalSale=totalSale, fanNum=fanNum, avgVideoSales=avgVideoSales, videoSales=videoSales,
  52. promoterId=promoterId)
  53. MysqlProUtils().Operate(sql=sql)
  54. @staticmethod
  55. def get_promoter_info():
  56. sql = """
  57. select a.promoter_id from ruixuan.kuaishou_promoter a
  58. left join ruixuan.promoter_sales_info b
  59. on a.promoter_id=b.promoter_id
  60. where b.promoter_id is null
  61. and a.media_id=2
  62. and a.create_time>=date_format(date_sub(now(),interval 10 day),'%Y-%m-%d')
  63. union all
  64. select a.promoter_id from ruixuan.jy_kuaishou_promoter a
  65. left join ruixuan.promoter_sales_info b
  66. on a.promoter_id=b.promoter_id
  67. where b.promoter_id is null
  68. and a.media_id=2
  69. and a.create_time>=date_format(date_sub(now(),interval 10 day),'%Y-%m-%d')
  70. """
  71. promoter_result = SpiderPromoterInfo.conn.QueryAll(sql)
  72. for promoter in promoter_result:
  73. promoter_id = promoter[0].decode('utf-8')
  74. SpiderPromoterInfo.get_promoter(promoter_id)
  75. time.sleep(30)
  76. if __name__ == '__main__':
  77. SpiderPromoterInfo.get_promoter_info()