gongzhonghao_follow_2.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/3/28
  4. import datetime
  5. import difflib
  6. import json
  7. import os
  8. import random
  9. import shutil
  10. import sys
  11. import time
  12. from hashlib import md5
  13. import requests
  14. import urllib3
  15. from selenium.webdriver import DesiredCapabilities
  16. from selenium.webdriver.chrome.service import Service
  17. from selenium.webdriver.common.by import By
  18. from selenium import webdriver
  19. sys.path.append(os.getcwd())
  20. from common.common import Common
  21. from common.feishu import Feishu
  22. from common.public import filter_word
  23. from common.publish import Publish
  24. from common.scheduling_db import MysqlHelper
  25. class GongzhonghaoFollow2:
  26. # 翻页参数
  27. begin = 0
  28. platform = "公众号"
  29. # 基础门槛规则
  30. @staticmethod
  31. def download_rule(video_dict):
  32. """
  33. 下载视频的基本规则
  34. :param video_dict: 视频信息,字典格式
  35. :return: 满足规则,返回 True;反之,返回 False
  36. """
  37. # 视频时长 20秒 - 45 分钟
  38. if 60 * 45 >= int(float(video_dict['duration'])) >= 20:
  39. # 宽或高
  40. if int(video_dict['video_width']) >= 0 or int(video_dict['video_height']) >= 0:
  41. return True
  42. else:
  43. return False
  44. else:
  45. return False
  46. @classmethod
  47. def title_like(cls, log_type, crawler, title, env):
  48. select_sql = f""" select * from crawler_video where platform="公众号" """
  49. video_list = MysqlHelper.get_values(log_type, crawler, select_sql, env, action="")
  50. if len(video_list) == 0:
  51. return None
  52. for video_dict in video_list:
  53. video_title = video_dict["video_title"]
  54. if difflib.SequenceMatcher(None, title, video_title).quick_ratio() >= 0.8:
  55. return True
  56. else:
  57. pass
  58. # 获取 token
  59. @classmethod
  60. def get_token(cls, log_type, crawler):
  61. while True:
  62. try:
  63. sheet = Feishu.get_values_batch(log_type, crawler, "I4aeh3")
  64. if sheet is None:
  65. time.sleep(1)
  66. continue
  67. token = sheet[0][1]
  68. cookie = sheet[1][1]
  69. gzh_name = sheet[2][1]
  70. gzh_time = sheet[3][1]
  71. token_dict = {'token': token, 'cookie': cookie, 'gzh_name': gzh_name, 'gzh_time': gzh_time}
  72. return token_dict
  73. except Exception as e:
  74. Common.logger(log_type, crawler).error(f"get_cookie_token异常:{e}\n")
  75. # 获取用户 fakeid
  76. @classmethod
  77. def get_fakeid(cls, log_type, crawler, user, index):
  78. try:
  79. while True:
  80. token_dict = cls.get_token(log_type, crawler)
  81. url = "https://mp.weixin.qq.com/cgi-bin/searchbiz?"
  82. headers = {
  83. "accept": "*/*",
  84. "accept-encoding": "gzip, deflate, br",
  85. "accept-language": "zh-CN,zh;q=0.9",
  86. "referer": "https://mp.weixin.qq.com/cgi-bin/appmsg?"
  87. "t=media/appmsg_edit_v2&action=edit&isNew=1"
  88. "&type=77&createType=5&token=1011071554&lang=zh_CN",
  89. 'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
  90. "sec-ch-ua-mobile": "?0",
  91. "sec-ch-ua-platform": '"Windows"',
  92. "sec-fetch-dest": "empty",
  93. "sec-fetch-mode": "cors",
  94. "sec-fetch-site": "same-origin",
  95. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
  96. " (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
  97. "x-requested-with": "XMLHttpRequest",
  98. 'cookie': token_dict['cookie'],
  99. }
  100. params = {
  101. "action": "search_biz",
  102. "begin": "0",
  103. "count": "5",
  104. "query": str(user),
  105. "token": token_dict['token'],
  106. "lang": "zh_CN",
  107. "f": "json",
  108. "ajax": "1",
  109. }
  110. urllib3.disable_warnings()
  111. r = requests.get(url=url, headers=headers, params=params, verify=False)
  112. if r.json()["base_resp"]["err_msg"] == "invalid session":
  113. Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
  114. Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
  115. if 20 >= datetime.datetime.now().hour >= 10:
  116. Feishu.bot(log_type, crawler, f"token_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
  117. time.sleep(60 * 10)
  118. continue
  119. if r.json()["base_resp"]["err_msg"] == "freq control":
  120. Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
  121. Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
  122. if 20 >= datetime.datetime.now().hour >= 10:
  123. Feishu.bot(log_type, crawler, f"公众号_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
  124. time.sleep(60 * 10)
  125. continue
  126. if "list" not in r.json() or len(r.json()["list"]) == 0:
  127. Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
  128. Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
  129. if 20 >= datetime.datetime.now().hour >= 10:
  130. Feishu.bot(log_type, crawler, f"公众号_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
  131. time.sleep(60 * 10)
  132. continue
  133. fakeid = r.json()["list"][int(index) - 1]["fakeid"]
  134. head_url = r.json()["list"][int(index) - 1]["round_head_img"]
  135. fakeid_dict = {'fakeid': fakeid, 'head_url': head_url}
  136. return fakeid_dict
  137. except Exception as e:
  138. Common.logger(log_type, crawler).error(f"get_fakeid异常:{e}\n")
  139. # 获取腾讯视频下载链接
  140. @classmethod
  141. def get_tencent_video_url(cls, log_type, crawler, video_id):
  142. try:
  143. url = 'https://vv.video.qq.com/getinfo?vids=' + str(video_id) + '&platform=101001&charge=0&otype=json'
  144. response = requests.get(url=url).text.replace('QZOutputJson=', '').replace('"};', '"}')
  145. response = json.loads(response)
  146. url = response['vl']['vi'][0]['ul']['ui'][0]['url']
  147. fvkey = response['vl']['vi'][0]['fvkey']
  148. video_url = url + str(video_id) + '.mp4?vkey=' + fvkey
  149. return video_url
  150. except Exception as e:
  151. Common.logger(log_type, crawler).error(f"get_tencent_video_url异常:{e}\n")
  152. @classmethod
  153. def get_video_url(cls, log_type, crawler, article_url, env):
  154. try:
  155. # 打印请求配置
  156. ca = DesiredCapabilities.CHROME
  157. ca["goog:loggingPrefs"] = {"performance": "ALL"}
  158. # 不打开浏览器运行
  159. chrome_options = webdriver.ChromeOptions()
  160. chrome_options.add_argument("headless")
  161. chrome_options.add_argument(
  162. f'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36')
  163. chrome_options.add_argument("--no-sandbox")
  164. # driver初始化
  165. if env == "prod":
  166. driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
  167. else:
  168. driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options, service=Service(
  169. '/Users/wangkun/Downloads/chromedriver/chromedriver_v111/chromedriver'))
  170. driver.implicitly_wait(10)
  171. # Common.logger(log_type, crawler).info('打开文章链接')
  172. driver.get(article_url)
  173. time.sleep(1)
  174. if len(driver.find_elements(By.XPATH, '//div[@class="js_video_poster video_poster"]/*[2]')) != 0:
  175. video_url = driver.find_element(
  176. By.XPATH, '//div[@class="js_video_poster video_poster"]/*[2]').get_attribute('src')
  177. elif len(driver.find_elements(By.XPATH, '//span[@class="js_tx_video_container"]/*[1]')) != 0:
  178. iframe = driver.find_element(By.XPATH, '//span[@class="js_tx_video_container"]/*[1]').get_attribute(
  179. 'src')
  180. video_id = iframe.split('vid=')[-1].split('&')[0]
  181. video_url = cls.get_tencent_video_url(log_type, crawler, video_id)
  182. else:
  183. video_url = 0
  184. driver.quit()
  185. return video_url
  186. except Exception as e:
  187. Common.logger(log_type, crawler).info(f'get_video_url异常:{e}\n')
  188. # 获取文章列表
  189. @classmethod
  190. def get_videoList(cls, log_type, crawler, user, index, oss_endpoint, env):
  191. try:
  192. while True:
  193. fakeid_dict = cls.get_fakeid(log_type, crawler, user, index)
  194. token_dict = cls.get_token(log_type, crawler)
  195. url = "https://mp.weixin.qq.com/cgi-bin/appmsg?"
  196. headers = {
  197. "accept": "*/*",
  198. "accept-encoding": "gzip, deflate, br",
  199. "accept-language": "zh-CN,zh;q=0.9",
  200. "referer": "https://mp.weixin.qq.com/cgi-bin/appmsg?"
  201. "t=media/appmsg_edit_v2&action=edit&isNew=1"
  202. "&type=77&createType=5&token=" + str(token_dict['token']) + "&lang=zh_CN",
  203. 'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
  204. "sec-ch-ua-mobile": "?0",
  205. "sec-ch-ua-platform": '"Windows"',
  206. "sec-fetch-dest": "empty",
  207. "sec-fetch-mode": "cors",
  208. "sec-fetch-site": "same-origin",
  209. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
  210. " (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
  211. "x-requested-with": "XMLHttpRequest",
  212. 'cookie': token_dict['cookie'],
  213. }
  214. params = {
  215. "action": "list_ex",
  216. "begin": str(cls.begin),
  217. "count": "5",
  218. "fakeid": fakeid_dict['fakeid'],
  219. "type": "9",
  220. "query": "",
  221. "token": str(token_dict['token']),
  222. "lang": "zh_CN",
  223. "f": "json",
  224. "ajax": "1",
  225. }
  226. urllib3.disable_warnings()
  227. r = requests.get(url=url, headers=headers, params=params, verify=False)
  228. if r.json()["base_resp"]["err_msg"] == "invalid session":
  229. Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
  230. Common.logger(log_type, crawler).info(f"get_videoList:{r.text}")
  231. if 20 >= datetime.datetime.now().hour >= 10:
  232. Feishu.bot(log_type, crawler, f"token_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
  233. time.sleep(60 * 10)
  234. continue
  235. if r.json()["base_resp"]["err_msg"] == "freq control":
  236. Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
  237. Common.logger(log_type, crawler).warning(f"get_videoList:{r.text}\n")
  238. if 20 >= datetime.datetime.now().hour >= 10:
  239. Feishu.bot(log_type, crawler, f"公众号_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
  240. time.sleep(60 * 10)
  241. continue
  242. if 'app_msg_list' not in r.json():
  243. Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
  244. Common.logger(log_type, crawler).warning(f"get_videoList:{r.text}\n")
  245. if 20 >= datetime.datetime.now().hour >= 10:
  246. Feishu.bot(log_type, crawler, f"公众号_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
  247. time.sleep(60 * 10)
  248. continue
  249. if len(r.json()['app_msg_list']) == 0:
  250. Common.logger(log_type, crawler).info('没有更多视频了\n')
  251. return
  252. else:
  253. cls.begin += 5
  254. app_msg_list = r.json()['app_msg_list']
  255. for article_url in app_msg_list:
  256. # title
  257. if 'title' in article_url:
  258. title = article_url['title'].replace('/', '').replace('\n', '') \
  259. .replace('.', '').replace('“', '').replace('”', '').replace(' ', '')
  260. else:
  261. title = 0
  262. # aid
  263. if 'aid' in article_url:
  264. aid = article_url['aid']
  265. else:
  266. aid = 0
  267. # create_time
  268. if 'create_time' in article_url:
  269. create_time = article_url['create_time']
  270. else:
  271. create_time = 0
  272. publish_time_stamp = int(create_time)
  273. publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time_stamp))
  274. avatar_url = fakeid_dict['head_url']
  275. # cover_url
  276. if 'cover' in article_url:
  277. cover_url = article_url['cover']
  278. else:
  279. cover_url = 0
  280. # article_url
  281. if 'link' in article_url:
  282. article_url = article_url['link']
  283. else:
  284. article_url = 0
  285. video_url = cls.get_video_url(log_type, crawler, article_url, env)
  286. video_dict = {
  287. 'video_id': aid,
  288. 'video_title': title,
  289. 'publish_time_stamp': publish_time_stamp,
  290. 'publish_time_str': publish_time_str,
  291. 'user_name': user,
  292. 'play_cnt': 0,
  293. 'comment_cnt': 0,
  294. 'like_cnt': 0,
  295. 'share_cnt': 0,
  296. 'user_id': fakeid_dict['fakeid'],
  297. 'avatar_url': avatar_url,
  298. 'cover_url': cover_url,
  299. 'article_url': article_url,
  300. 'video_url': video_url,
  301. 'session': f'gongzhonghao-follow-{int(time.time())}'
  302. }
  303. for k, v in video_dict.items():
  304. Common.logger(log_type, crawler).info(f"{k}:{v}")
  305. if int(time.time()) - publish_time_stamp >= 3600 * 24 * 3:
  306. Common.logger(log_type, crawler).info(f'发布时间{publish_time_str} > 3 天\n')
  307. cls.begin = 0
  308. return
  309. cls.download_publish(log_type, crawler, video_dict, oss_endpoint, env)
  310. Common.logger(log_type, crawler).info('随机休眠 60*3-60*8 秒\n')
  311. time.sleep(random.randint(60*5, 60*10))
  312. except Exception as e:
  313. Common.logger(log_type, crawler).error(f"get_videoList异常:{e}\n")
  314. @classmethod
  315. def repeat_video(cls, log_type, crawler, video_id, env):
  316. sql = f""" select * from crawler_video where platform="公众号" and out_video_id="{video_id}"; """
  317. repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env)
  318. return len(repeat_video)
  319. # 下载/上传
  320. @classmethod
  321. def download_publish(cls, log_type, crawler, video_dict, oss_endpoint, env):
  322. try:
  323. if video_dict['article_url'] == 0 or video_dict['video_url'] == 0:
  324. Common.logger(log_type, crawler).info("文章涉嫌违反相关法律法规和政策\n")
  325. # 标题敏感词过滤
  326. elif any(word if word in video_dict['video_title'] else False for word in
  327. filter_word(log_type, crawler, "公众号", env)) is True:
  328. Common.logger(log_type, crawler).info("标题已中过滤词\n")
  329. # 已下载判断
  330. elif cls.repeat_video(log_type, crawler, video_dict['video_id'], env) != 0:
  331. Common.logger(log_type, crawler).info("视频已下载\n")
  332. # 标题相似度
  333. elif cls.title_like(log_type, crawler, video_dict['video_title'], env) is True:
  334. Common.logger(log_type, crawler).info(f'标题相似度>=80%:{video_dict["video_title"]}\n')
  335. else:
  336. # 下载视频
  337. Common.download_method(log_type=log_type, crawler=crawler, text="video",
  338. title=video_dict["video_title"], url=video_dict["video_url"])
  339. md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
  340. # 获取视频时长
  341. ffmpeg_dict = Common.ffmpeg(log_type, crawler,
  342. f"./{crawler}/videos/{video_dict['video_title']}/video.mp4")
  343. if ffmpeg_dict is None:
  344. # 删除视频文件夹
  345. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  346. Common.logger(log_type, crawler).info("视频size=0,删除成功\n")
  347. return
  348. video_dict["video_width"] = ffmpeg_dict["width"]
  349. video_dict["video_height"] = ffmpeg_dict["height"]
  350. video_dict["duration"] = ffmpeg_dict["duration"]
  351. video_size = ffmpeg_dict["size"]
  352. Common.logger(log_type, crawler).info(f'video_width:{video_dict["video_width"]}')
  353. Common.logger(log_type, crawler).info(f'video_height:{video_dict["video_height"]}')
  354. Common.logger(log_type, crawler).info(f'duration:{video_dict["duration"]}')
  355. Common.logger(log_type, crawler).info(f'video_size:{video_size}')
  356. # 视频size=0,直接删除
  357. if int(video_size) == 0 or cls.download_rule(video_dict) is False:
  358. # 删除视频文件夹
  359. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  360. Common.logger(log_type, crawler).info("视频size=0,删除成功\n")
  361. return
  362. # 下载封面
  363. Common.download_method(log_type=log_type, crawler=crawler, text="cover",
  364. title=video_dict["video_title"], url=video_dict["cover_url"])
  365. # 保存视频信息至 "./videos/{video_title}/info.txt"
  366. Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
  367. # 上传视频
  368. Common.logger(log_type, crawler).info("开始上传视频...")
  369. strategy = "定向爬虫策略"
  370. our_video_id = Publish.upload_and_publish(log_type=log_type,
  371. crawler=crawler,
  372. strategy=strategy,
  373. our_uid="follow",
  374. oss_endpoint=oss_endpoint,
  375. env=env)
  376. if env == 'prod':
  377. our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{str(our_video_id)}/info"
  378. else:
  379. our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{str(our_video_id)}/info"
  380. Common.logger(log_type, crawler).info("视频上传完成")
  381. if our_video_id is None:
  382. # 删除视频文件夹
  383. shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
  384. return
  385. # 视频信息保存数据库
  386. rule_dict = {
  387. "duration": {"min": 20, "max": 45 * 60},
  388. "publish_day": {"min": 3}
  389. }
  390. insert_sql = f""" insert into crawler_video(video_id,
  391. out_user_id,
  392. platform,
  393. strategy,
  394. out_video_id,
  395. video_title,
  396. cover_url,
  397. video_url,
  398. duration,
  399. publish_time,
  400. play_cnt,
  401. crawler_rule,
  402. width,
  403. height)
  404. values({our_video_id},
  405. "{video_dict['user_id']}",
  406. "{cls.platform}",
  407. "定向爬虫策略",
  408. "{video_dict['video_id']}",
  409. "{video_dict['video_title']}",
  410. "{video_dict['cover_url']}",
  411. "{video_dict['video_url']}",
  412. {int(video_dict['duration'])},
  413. "{video_dict['publish_time_str']}",
  414. {int(video_dict['play_cnt'])},
  415. '{json.dumps(rule_dict)}',
  416. {int(video_dict['video_width'])},
  417. {int(video_dict['video_height'])}) """
  418. Common.logger(log_type, crawler).info(f"insert_sql:{insert_sql}")
  419. MysqlHelper.update_values(log_type, crawler, insert_sql, env)
  420. Common.logger(log_type, crawler).info('视频信息插入数据库成功!')
  421. # 视频写入飞书
  422. Feishu.insert_columns(log_type, crawler, "47e39d", "ROWS", 1, 2)
  423. # 视频ID工作表,首行写入数据
  424. upload_time = int(time.time())
  425. values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time)),
  426. "用户主页",
  427. video_dict['video_title'],
  428. video_dict['video_id'],
  429. our_video_link,
  430. int(video_dict['duration']),
  431. f"{video_dict['video_width']}*{video_dict['video_height']}",
  432. video_dict['publish_time_str'],
  433. video_dict['user_name'],
  434. video_dict['user_id'],
  435. video_dict['avatar_url'],
  436. video_dict['cover_url'],
  437. video_dict['article_url'],
  438. video_dict['video_url']]]
  439. time.sleep(0.5)
  440. Feishu.update_values(log_type, crawler, "47e39d", "F2:Z2", values)
  441. Common.logger(log_type, crawler).info('视频下载/上传成功\n')
  442. except Exception as e:
  443. Common.logger(log_type, crawler).error(f"download_publish异常:{e}\n")
  444. @classmethod
  445. def get_users(cls):
  446. # user_sheet = Feishu.get_values_batch("follow", 'gongzhonghao', 'Bzv72P')
  447. # user_list = []
  448. # for i in range(41, 81):
  449. # user_name = user_sheet[i][0]
  450. # index = user_sheet[i][1]
  451. # user_dict = {
  452. # "user_name": user_name,
  453. # "index": index,
  454. # }
  455. # user_list.append(user_dict)
  456. # print(len(user_list))
  457. # print(user_list)
  458. user_list = [{'user_name': '小分子生物活性肽', 'index': 1}, {'user_name': '张小妹美食', 'index': 1}, {'user_name': '万物归息', 'index': 1}, {'user_name': '神州红魂', 'index': 1}, {'user_name': '音乐早餐', 'index': 1}, {'user_name': '1条末读消息', 'index': 1}, {'user_name': '环球文摘', 'index': 1}, {'user_name': '精彩有余', 'index': 1}, {'user_name': '一起训练吧', 'index': 1}, {'user_name': '1条重要消息', 'index': 1}, {'user_name': '太上养身', 'index': 1}, {'user_name': '懂点养身秘诀', 'index': 1}, {'user_name': '送乐者', 'index': 1}, {'user_name': '蜂业小百科', 'index': 1}, {'user_name': '健康与养身秘诀', 'index': 1}, {'user_name': '有心人r', 'index': 1}, {'user_name': '古诗词世界', 'index': 1}, {'user_name': '晨间悦读', 'index': 1}, {'user_name': '养身有诀窍', 'index': 1}, {'user_name': '退休族信息圈', 'index': 1}, {'user_name': '艾公铁粉团', 'index': 1}, {'user_name': '酸甜苦辣麻咸', 'index': 1}, {'user_name': '日常生活小帮手', 'index': 1}, {'user_name': '小帅的精彩视频', 'index': 1}, {'user_name': '养身常识小窍门', 'index': 1}, {'user_name': '医学养身技巧', 'index': 1}, {'user_name': '退休圈', 'index': 1}, {'user_name': '生活小助手', 'index': 1}, {'user_name': '经典老歌曲好听的音乐', 'index': 1}, {'user_name': '黑马快讯', 'index': 1}, {'user_name': '绝妙经典', 'index': 1}, {'user_name': '深读时策', 'index': 1}, {'user_name': '健康与生活大全', 'index': 1}, {'user_name': '李肃论道', 'index': 1}, {'user_name': '爱国者吹锋号', 'index': 1}, {'user_name': '兵心可鉴', 'index': 1}, {'user_name': '精选动心金曲', 'index': 1}, {'user_name': '爱二胡群', 'index': 1}, {'user_name': '数码科技大爆炸', 'index': 1}, {'user_name': '何静同学', 'index': 1}]
  459. return user_list
  460. @classmethod
  461. def get_all_videos(cls, log_type, crawler, oss_endpoint, env):
  462. user_list = cls.get_users()
  463. for user_dict in user_list:
  464. try:
  465. user_name = user_dict['user_name']
  466. index = user_dict['index']
  467. Common.logger(log_type, crawler).info(f'获取 {user_name} 公众号视频\n')
  468. cls.get_videoList(log_type, crawler, user_name, index, oss_endpoint, env)
  469. cls.begin = 0
  470. Common.logger(log_type, crawler).info('随机休眠 60*5, 60*10 秒\n')
  471. time.sleep(random.randint(60*5, 60*10))
  472. except Exception as e:
  473. Common.logger(log_type, crawler).info(f'get_all_videos异常:{e}\n')
  474. if __name__ == "__main__":
  475. print(GongzhonghaoFollow2.get_users())
  476. # GongzhonghaoFollow.get_users()
  477. # GongzhonghaoFollow.get_videoList(log_type="follow",
  478. # crawler="gongzhonghao",
  479. # user="香音难忘",
  480. # index=1,
  481. # oss_endpoint="out",
  482. # env="dev")
  483. pass