zhihu_follow.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/10/31
  4. import os
  5. import sys
  6. import time
  7. import requests
  8. import urllib3
  9. sys.path.append(os.getcwd())
  10. from main.common import Common
  11. from main.feishu_lib import Feishu
  12. from main.follow_publish import Publish
  13. proxies = {'http': None, 'https': None}
  14. class ZhihuFollow:
  15. offset = 0
  16. @classmethod
  17. def get_users_from_feishu(cls, log_type):
  18. try:
  19. user_sheet = Feishu.get_values_batch(log_type, 'zhihu', '4NTla6')
  20. user_dict = {}
  21. for i in range(1, len(user_sheet)):
  22. user_name = user_sheet[i][0]
  23. url_token = user_sheet[i][1]
  24. referer = user_sheet[i][2]
  25. our_id = user_sheet[i][3]
  26. if user_name is None or url_token is None or our_id is None:
  27. pass
  28. else:
  29. user_dict[user_name] = str(url_token) + ',' + str(referer) + ',' + str(our_id)
  30. return user_dict
  31. except Exception as e:
  32. Common.logger(log_type).error('get_users_from_feishu异常:{}\n', e)
  33. @classmethod
  34. def get_follow_feeds(cls, log_type, url_token, referer, our_uid, env):
  35. while True:
  36. Common.logger(log_type).info('offset:{}', cls.offset)
  37. url = "https://www.zhihu.com//api//v4//members//" + str(url_token) + "//zvideos?"
  38. headers = {
  39. 'pragma': 'no-cache',
  40. 'cache-control': 'no-cache',
  41. 'x-zse-93': '101_3_3.0',
  42. 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
  43. 'x-zst-81': '3_2.0aR_sn77yn6O92wOB8hPZnQr0EMYxc4f18wNBUgpTQ6nxERFZMRY0-4Lm-h3_tufIwJS8gcxTgJS_AuPZNcXCTwxI78YxEM20s4PGDwN8gGcYAupMWufIoLVqr4gxrRPOI0cY7HL8qun9g93mFukyigcmebS_FwOYPRP0E4rZUrN9DDom3hnynAUMnAVPF_PhaueTF7C89Uw8_w2YiDNBOcC_ggeL2HN1fTN0WvUq_UY9aCLBMQO0VvUfoTp9y9eTV4xC8b3YCGNs2bSfXwCZpUw06hcMJ_w0B8NmhvwMcGe9iqCZlcSftv3qTug_-BVqgwL1r7H99CeV24C9_Up9HqHmj9CsqUH8tBNLUbxm1gOprAO_6CL0Vg_z9DVs9rS1R9x08wxG2Cxme9FLlUc9jJu027gB3UVBJqpBbqUCrwo1nqHmggO_Nr9_BqcxfC2GnvSqNcxyIDOfiuw9dgCC27emaUpMxuVqquFYwUSL2BXs',
  44. 'accept': '*/*',
  45. 'referer': referer,
  46. 'sec-ch-ua': '"Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99"',
  47. 'sec-ch-ua-mobile': '?0',
  48. 'sec-ch-ua-platform': '"macOS"',
  49. 'sec-fetch-dest': 'empty',
  50. 'sec-fetch-mode': 'cors',
  51. 'sec-fetch-site': 'same-origin',
  52. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
  53. 'x-ab-pb': 'CsIBCAAbAD8ARwC0AGkBagF0ATsCzALXAtgCTwNQA6ADoQOiA7cD8wP0AzMEjASNBKYE1gQRBVEFiwWMBZ4FMAYxBusGJwd3B3gH2AfcB90HZwh0CHYIeQjaCD8JQglgCY0JwwnECcUJxgnHCcgJyQnKCcsJzAnRCfQJBApJCmUKawqYCqUKqQq+CsQK1ArdCu0K/Qr+CjsLPAtDC0YLcQt2C4ULhwuNC8AL1wvgC+UL5gssDDgMcQyPDKwMuQzDDMkM+AwSYQEAAAAAAAAAAAMAAAAAAAAAAAAAAAQEAAQAAAAAAQAAAQAAAAACAgQAAAYAAAEBAAAAAAAAAAAAAAAAAwAAAAABAAAAAQEAAAAAAQABAAAAAAAFAAIBAAAGAgYAAAECAAA=',
  54. 'x-requested-with': 'fetch',
  55. 'accept-encoding': 'gzip, deflate, br',
  56. 'x-zse-96': '2.0_wSyMHDQ7MZYfDZWRCM=Il3PaIuFuaTZf=spPXrAiJo83rlG65AU+b6IIBIr5nJ5L',
  57. }
  58. params = {
  59. 'offset': str(cls.offset),
  60. 'limit': '20',
  61. 'similar_aggregation': True,
  62. 'include': 'similar_zvideo,creation_relationship',
  63. }
  64. cookies = {
  65. '_zap': 'a17e5882-775f-49dd-b541-e854c0299999',
  66. 'd_c0': '"AFAcR4hr0RKPTn2-RL935cm51KQZn9-Xlb0=|1616071586"',
  67. '_9755xjdesxxd_': '32',
  68. 'YD00517437729195%3AWM_TID': 'yR6Kt%2FwMI2xEFEQRVBYrou2J%2F14yfdzt',
  69. 'q_c1': '947ece3f1ccd4ccd83b718c113fe3935|1658911548000|1658911548000',
  70. '_xsrf': 'cAM8ovVh43f0oJE2erl6ho8Y4CTZhFKF',
  71. '__snaker__id': 'mqTPtP3IwbuoHA2K',
  72. 'gdxidpyhxdE': 'a2d%2FeD%2BEUNxnnTaLDjQfd28sI39g3pnKAqS%2BmodWMqYcMa3AMzV5eom2APR2z5rDHAVvfubp%2BWEzkcxdb9UjWNT0gbshTpBmHzU1%2BMB%2BfW5sAAUz1%5CTWIWbP34z7SV4TCB%2BfbQtoAdRAZANzEbcollrLlPmyAG%2FtPICs5ewAvswneclw%3A1666061422009',
  73. 'YD00517437729195%3AWM_NI': 'bTzKLUbqXTrTGVFS91056cj27L%2F9PQ8MG8ofPHnJc98014ktS5xa09N8yJZho7jEeQfeueH0sJLDH5YmaA2nCP1kQ1jaB4FChGGNA7HbM%2B5yRCuYOmGjfIs5LOdoxm1WSHY%3D',
  74. 'YD00517437729195%3AWM_NIKE': '9ca17ae2e6ffcda170e2e6eeb2f5628de7a5b2db5cfc8e8eb6d85f929e8aacc150b6ed9bd8b33c93afc089cf2af0fea7c3b92aa28cb6accf5fa2af98b5f160858a8ab4bc3bf4ebfa84e93af594e1dad35bfc9389d9ee6e9498a2abe233fcf0ffd5ea8091ebb882b3338ee8b7abd964ade9a6a6e85ba6bbbb86cb3cb19684a5cb3f9bb3afa2b1668190ff8cd43baabf8ed5c549ac9989afc43d8cbe83ccb873929dbbbace6785b6aaaaf23f9091ac90fb67f3899da9dc37e2a3',
  75. 'captcha_ticket_v2': '2|1:0|10:1666060537|17:captcha_ticket_v2|704:eyJ2YWxpZGF0ZSI6IkNOMzFfVkk0TmhfRVJ1SGxhQW4yV0ZHWFlXTjdIWXM3TnZQSUFMY19MRGdVV1dMX3Vody0wMFAtYnA0UXBFVnI5akI1NFNVajhZVEpLeXVLODJWajJoVU83MnBya2xyLi5TalExekwyZ3hQU3JjZTI4TkJweTh2NEg5QjFyVUlBME1zSGtfUlRqQ3lDd1BkQ2Y3c3J3WWl0V0Qyci5FTWV6eEJRMUdQcGlWS2dCXzRkQzhSWmNMT1ZmWnlxUDZWbTh6ZEdDdmVnVkhFTTFGVWNpNVJRV2NWLjZ6V2V4UUpJOWJibUdRZHpJQ0VQUFlZZU5ObVBKOTlKMUw1OWFxUmRxUzVtY1hDbXBsRzVBTnM0LmEyS1BDRGNTYWVTWUlpMFdfc0JlTE44QlZCXzFkWjFLV2xoUmx3bkR6QjJMdUdOcm1IRXRaejQ2T0ViVzhVS3ZSNjU2YUJEUk9tYUNscVM5cDk2T2cwY1JadlhEZFZOSlFSeG0wNkRUMEs5cHRLLS1hajFWaWtEMnp4UU50MEpFZE9PRGs2RWtqdklnWnM0S0s0bUVBd0tGS2FIMklJaXVod1dMck9WOGdKLUpwNjlYNU9hWWxNcEtCbk9pU2JYNUJfUnBmeU1hLlAwbUlBYXYwbnBvY0xRWmdMMXJpelN5OFVaVl9QMXduWTByR1BtMyJ9|557dafa54cac0a5cd55b3e8ebbb626e6817010e985c2a3c60a82fb00bcb8b72a',
  76. 'captcha_session_v2': '2|1:0|10:1666060537|18:captcha_session_v2|88:SUlnbE5uR29rUC83Z0VvWVpjTS9JV3VKSFFYTUl4T1hFbVdZZnB2Wms1Z1cxYkZFQndYWHhqVDRGWEE0NzVaTQ==|a40c62b74a94ad618205342e3f87091b525a50fe9c8f153af02b08a3569fa7c0',
  77. 'z_c0': '2|1:0|10:1666767387|4:z_c0|92:Mi4xVFdsTlB3QUFBQUFBVUJ4SGlHdlJFaVlBQUFCZ0FsVk5CVjg3WkFBOTBXb185c2wyUjJ6ZmQ1OTYtamliYWJWTUp3|abd71d40da50ae308430e26ce358d34cd4bccdfe575bf544d212019c7189ecdb',
  78. 'Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49': '1665574748,1666678329,1667194593',
  79. 'SESSIONID': 'hyrUgL9IzongRfviGSTmGR2sDyVliSwHuWy0fXouVk7',
  80. 'JOID': 'W14WBkoyfRA9faU0WD7qwUz2wuJAVQFkbBLmCBdAHXtcK8tNNNogTVJ6rzdabb3cImOxRThXGFkflrdU1CD0UWI=',
  81. 'osd': 'U10VAU46fhM6ea03WznuyU_1xeZIVgJjaBrlCxBEFXhfLM9FN9knSVp5rDBeZb7fJWe5RjtQHFEclbBQ3CP3VmY=',
  82. 'tst': 'v',
  83. 'NOT_UNREGISTER_WAITING': '1',
  84. 'Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49': '1667373061',
  85. 'unlock_ticket': 'AGBWwkpQuhUmAAAAYAJVTQ0fYmOTbjeHqRp3XiDPD3ZVB5KkeaEeYw==',
  86. 'KLBRSID': '031b5396d5ab406499e2ac6fe1bb1a43|1667373074|1667370552',
  87. }
  88. urllib3.disable_warnings()
  89. response = requests.get(url=url, headers=headers, params=params, cookies=cookies, verify=False, proxies=proxies)
  90. cls.offset += 20
  91. if 'data' not in response.json():
  92. Common.logger(log_type).error('response:{}\n', response.text)
  93. elif len(response.json()['data']) == 0:
  94. Common.logger(log_type).error('response:{}\n', response.text)
  95. else:
  96. feeds = response.json()['data']
  97. is_end = response.json()['paging']['is_end']
  98. for i in range(len(feeds)):
  99. # video_title
  100. if 'title' not in feeds[i]:
  101. video_title = 0
  102. else:
  103. video_title = feeds[i]['title']
  104. # video_id
  105. if 'video' not in feeds[i]:
  106. video_id = 0
  107. elif 'video_id' not in feeds[i]['video']:
  108. video_id = 0
  109. else:
  110. video_id = feeds[i]['video']['video_id']
  111. # play_cnt
  112. if 'play_count' not in feeds[i]:
  113. play_cnt = 0
  114. else:
  115. play_cnt = feeds[i]['play_count']
  116. # comment_cnt
  117. if 'comment_count' not in feeds[i]:
  118. comment_cnt = 0
  119. else:
  120. comment_cnt = feeds[i]['comment_count']
  121. # like_cnt
  122. if 'liked_count' not in feeds[i]:
  123. like_cnt = 0
  124. else:
  125. like_cnt = feeds[i]['liked_count']
  126. # share_cnt
  127. if 'share_count' not in feeds[i]:
  128. share_cnt = 0
  129. else:
  130. share_cnt = feeds[i]['share_count']
  131. # voteup_cnt 赞同数
  132. if 'voteup_count' not in feeds[i]:
  133. voteup_cnt = 0
  134. else:
  135. voteup_cnt = feeds[i]['voteup_count']
  136. # publish_time
  137. if 'published_at' not in feeds[i]:
  138. publish_time = 0
  139. else:
  140. publish_time = feeds[i]['published_at']
  141. # duration
  142. if 'video' not in feeds[i]:
  143. duration = 0
  144. elif 'duration' not in feeds[i]['video']:
  145. duration = 0
  146. else:
  147. duration = feeds[i]['video']['duration']
  148. # width / height / video_url
  149. if 'video' not in feeds[i]:
  150. video_width = 0
  151. video_height = 0
  152. video_url = 0
  153. elif 'playlist' in feeds[i]['video'] and 'fhd' in feeds[i]['video']['playlist'] \
  154. and 'width' in feeds[i]['video']['playlist']['fhd'] \
  155. and 'height' in feeds[i]['video']['playlist']['fhd'] \
  156. and 'play_url' in feeds[i]['video']['playlist']['fhd']:
  157. video_width = feeds[i]['video']['playlist']['fhd']['width']
  158. video_height = feeds[i]['video']['playlist']['fhd']['height']
  159. video_url = feeds[i]['video']['playlist']['fhd']['play_url']
  160. elif 'playlist' in feeds[i]['video'] and 'fhd' in feeds[i]['video']['playlist'] \
  161. and 'width' in feeds[i]['video']['playlist']['fhd'] \
  162. and 'height' in feeds[i]['video']['playlist']['fhd'] \
  163. and 'url' in feeds[i]['video']['playlist']['fhd']:
  164. video_width = feeds[i]['video']['playlist']['fhd']['width']
  165. video_height = feeds[i]['video']['playlist']['fhd']['height']
  166. video_url = feeds[i]['video']['playlist']['fhd']['url']
  167. elif 'playlist' in feeds[i]['video'] and 'hd' in feeds[i]['video']['playlist'] \
  168. and 'width' in feeds[i]['video']['playlist']['hd'] \
  169. and 'height' in feeds[i]['video']['playlist']['hd'] \
  170. and 'play_url' in feeds[i]['video']['playlist']['hd']:
  171. video_width = feeds[i]['video']['playlist']['hd']['width']
  172. video_height = feeds[i]['video']['playlist']['hd']['height']
  173. video_url = feeds[i]['video']['playlist']['hd']['play_url']
  174. elif 'playlist' in feeds[i]['video'] and 'hd' in feeds[i]['video']['playlist'] \
  175. and 'width' in feeds[i]['video']['playlist']['hd'] \
  176. and 'height' in feeds[i]['video']['playlist']['hd'] \
  177. and 'url' in feeds[i]['video']['playlist']['hd']:
  178. video_width = feeds[i]['video']['playlist']['hd']['width']
  179. video_height = feeds[i]['video']['playlist']['hd']['height']
  180. video_url = feeds[i]['video']['playlist']['hd']['url']
  181. elif 'playlist' in feeds[i]['video'] and 'ld' in feeds[i]['video']['playlist'] \
  182. and 'width' in feeds[i]['video']['playlist']['ld'] \
  183. and 'height' in feeds[i]['video']['playlist']['ld'] \
  184. and 'play_url' in feeds[i]['video']['playlist']['ld']:
  185. video_width = feeds[i]['video']['playlist']['ld']['width']
  186. video_height = feeds[i]['video']['playlist']['ld']['height']
  187. video_url = feeds[i]['video']['playlist']['ld']['play_url']
  188. elif 'playlist' in feeds[i]['video'] and 'ld' in feeds[i]['video']['playlist'] \
  189. and 'width' in feeds[i]['video']['playlist']['ld'] \
  190. and 'height' in feeds[i]['video']['playlist']['ld'] \
  191. and 'url' in feeds[i]['video']['playlist']['ld']:
  192. video_width = feeds[i]['video']['playlist']['ld']['width']
  193. video_height = feeds[i]['video']['playlist']['ld']['height']
  194. video_url = feeds[i]['video']['playlist']['ld']['url']
  195. elif 'playlist' in feeds[i]['video'] and 'sd' in feeds[i]['video']['playlist'] \
  196. and 'width' in feeds[i]['video']['playlist']['sd'] \
  197. and 'height' in feeds[i]['video']['playlist']['sd'] \
  198. and 'play_url' in feeds[i]['video']['playlist']['sd']:
  199. video_width = feeds[i]['video']['playlist']['sd']['width']
  200. video_height = feeds[i]['video']['playlist']['sd']['height']
  201. video_url = feeds[i]['video']['playlist']['sd']['play_url']
  202. elif 'playlist' in feeds[i]['video'] and 'sd' in feeds[i]['video']['playlist'] \
  203. and 'width' in feeds[i]['video']['playlist']['sd'] \
  204. and 'height' in feeds[i]['video']['playlist']['sd'] \
  205. and 'url' in feeds[i]['video']['playlist']['sd']:
  206. video_width = feeds[i]['video']['playlist']['sd']['width']
  207. video_height = feeds[i]['video']['playlist']['sd']['height']
  208. video_url = feeds[i]['video']['playlist']['sd']['url']
  209. elif 'playlist_v2' in feeds[i]['video'] and 'fhd' in feeds[i]['video']['playlist_v2'] \
  210. and 'width' in feeds[i]['video']['playlist_v2']['fhd'] \
  211. and 'height' in feeds[i]['video']['playlist_v2']['fhd'] \
  212. and 'play_url' in feeds[i]['video']['playlist_v2']['fhd']:
  213. video_width = feeds[i]['video']['playlist_v2']['fhd']['width']
  214. video_height = feeds[i]['video']['playlist_v2']['fhd']['height']
  215. video_url = feeds[i]['video']['playlist_v2']['fhd']['play_url']
  216. elif 'playlist_v2' in feeds[i]['video'] and 'fhd' in feeds[i]['video']['playlist_v2'] \
  217. and 'width' in feeds[i]['video']['playlist_v2']['fhd'] \
  218. and 'height' in feeds[i]['video']['playlist_v2']['fhd'] \
  219. and 'url' in feeds[i]['video']['playlist_v2']['fhd']:
  220. video_width = feeds[i]['video']['playlist_v2']['fhd']['width']
  221. video_height = feeds[i]['video']['playlist_v2']['fhd']['height']
  222. video_url = feeds[i]['video']['playlist_v2']['fhd']['url']
  223. elif 'playlist_v2' in feeds[i]['video'] and 'hd' in feeds[i]['video']['playlist_v2'] \
  224. and 'width' in feeds[i]['video']['playlist_v2']['hd'] \
  225. and 'height' in feeds[i]['video']['playlist_v2']['hd'] \
  226. and 'play_url' in feeds[i]['video']['playlist_v2']['hd']:
  227. video_width = feeds[i]['video']['playlist_v2']['hd']['width']
  228. video_height = feeds[i]['video']['playlist_v2']['hd']['height']
  229. video_url = feeds[i]['video']['playlist_v2']['hd']['play_url']
  230. elif 'playlist_v2' in feeds[i]['video'] and 'hd' in feeds[i]['video']['playlist_v2'] \
  231. and 'width' in feeds[i]['video']['playlist_v2']['hd'] \
  232. and 'height' in feeds[i]['video']['playlist_v2']['hd'] \
  233. and 'url' in feeds[i]['video']['playlist_v2']['hd']:
  234. video_width = feeds[i]['video']['playlist_v2']['hd']['width']
  235. video_height = feeds[i]['video']['playlist_v2']['hd']['height']
  236. video_url = feeds[i]['video']['playlist_v2']['hd']['url']
  237. elif 'playlist_v2' in feeds[i]['video'] and 'ld' in feeds[i]['video']['playlist_v2'] \
  238. and 'width' in feeds[i]['video']['playlist_v2']['ld'] \
  239. and 'height' in feeds[i]['video']['playlist_v2']['ld'] \
  240. and 'play_url' in feeds[i]['video']['playlist_v2']['ld']:
  241. video_width = feeds[i]['video']['playlist_v2']['ld']['width']
  242. video_height = feeds[i]['video']['playlist_v2']['ld']['height']
  243. video_url = feeds[i]['video']['playlist_v2']['ld']['play_url']
  244. elif 'playlist_v2' in feeds[i]['video'] and 'ld' in feeds[i]['video']['playlist_v2'] \
  245. and 'width' in feeds[i]['video']['playlist_v2']['ld'] \
  246. and 'height' in feeds[i]['video']['playlist_v2']['ld'] \
  247. and 'url' in feeds[i]['video']['playlist_v2']['ld']:
  248. video_width = feeds[i]['video']['playlist_v2']['ld']['width']
  249. video_height = feeds[i]['video']['playlist_v2']['ld']['height']
  250. video_url = feeds[i]['video']['playlist_v2']['ld']['url']
  251. elif 'playlist_v2' in feeds[i]['video'] and 'sd' in feeds[i]['video']['playlist_v2'] \
  252. and 'width' in feeds[i]['video']['playlist_v2']['sd'] \
  253. and 'height' in feeds[i]['video']['playlist_v2']['sd'] \
  254. and 'play_url' in feeds[i]['video']['playlist_v2']['sd']:
  255. video_width = feeds[i]['video']['playlist_v2']['sd']['width']
  256. video_height = feeds[i]['video']['playlist_v2']['sd']['height']
  257. video_url = feeds[i]['video']['playlist_v2']['sd']['play_url']
  258. elif 'playlist_v2' in feeds[i]['video'] and 'sd' in feeds[i]['video']['playlist_v2'] \
  259. and 'width' in feeds[i]['video']['playlist_v2']['sd'] \
  260. and 'height' in feeds[i]['video']['playlist_v2']['sd'] \
  261. and 'url' in feeds[i]['video']['playlist_v2']['sd']:
  262. video_width = feeds[i]['video']['playlist_v2']['sd']['width']
  263. video_height = feeds[i]['video']['playlist_v2']['sd']['height']
  264. video_url = feeds[i]['video']['playlist_v2']['sd']['url']
  265. else:
  266. video_width = 0
  267. video_height = 0
  268. video_url = 0
  269. # cover_url
  270. if 'video' not in feeds[i]:
  271. cover_url = 0
  272. elif 'thumbnail' not in feeds[i]['video']:
  273. cover_url = 0
  274. else:
  275. cover_url = feeds[i]['video']['thumbnail']
  276. # user_name / uid / user_type / url_token / avatar_url
  277. if 'author' not in feeds[i]:
  278. user_name = 0
  279. uid = 0
  280. user_type = 0
  281. url_token = 0
  282. avatar_url = 0
  283. elif 'author' in feeds[i] \
  284. and 'name' in feeds[i]['author'] \
  285. and 'uid' in feeds[i]['author'] \
  286. and 'user_type' in feeds[i]['author'] \
  287. and 'url_token' in feeds[i]['author'] \
  288. and 'avatar_url_template' in feeds[i]['author']:
  289. user_name = feeds[i]['author']['name']
  290. uid = feeds[i]['author']['uid']
  291. user_type = feeds[i]['author']['user_type']
  292. url_token = feeds[i]['author']['url_token']
  293. avatar_url = feeds[i]['author']['avatar_url_template']
  294. elif 'author' in feeds[i] \
  295. and 'name' in feeds[i]['author'] \
  296. and 'uid' in feeds[i]['author'] \
  297. and 'user_type' in feeds[i]['author'] \
  298. and 'url_token' in feeds[i]['author'] \
  299. and 'avatar_url' in feeds[i]['author']:
  300. user_name = feeds[i]['author']['name']
  301. uid = feeds[i]['author']['uid']
  302. user_type = feeds[i]['author']['user_type']
  303. url_token = feeds[i]['author']['url_token']
  304. avatar_url = feeds[i]['author']['avatar_url']
  305. else:
  306. user_name = 0
  307. uid = 0
  308. user_type = 0
  309. url_token = 0
  310. avatar_url = 0
  311. Common.logger(log_type).info('video_title:{}', video_title)
  312. Common.logger(log_type).info('duration:{}秒', int(duration))
  313. Common.logger(log_type).info(
  314. 'publish_time:{}', time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(publish_time)))
  315. if video_title == 0 or cover_url == 0 or video_url == 0:
  316. Common.logger(log_type).info('无效视频\n')
  317. elif int(time.time()) - int(publish_time) >= 3600*24*10:
  318. Common.logger(log_type).info('发布时间:{} 超过30天\n', time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(publish_time)))
  319. cls.offset = 0
  320. return
  321. elif int(duration) < 60:
  322. Common.logger(log_type).info('时长{}<60秒\n', int(duration))
  323. elif str(video_id) in [x for y in Feishu.get_values_batch(log_type, 'zhihu', '8871e3') for x in y]:
  324. Common.logger(log_type).info('视频已下载\n')
  325. elif str(video_id) in [x for y in Feishu.get_values_batch(log_type, 'zhihu', '4MGuux') for x in y]:
  326. Common.logger(log_type).info('视频已下载\n')
  327. else:
  328. Common.download_method(log_type, 'cover', video_title, cover_url)
  329. Common.download_method(log_type, 'video', video_title, video_url)
  330. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  331. with open("./videos/" + video_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  332. f_a.write(str(video_id) + "\n" +
  333. str(video_title) + "\n" +
  334. str(int(duration)) + "\n" +
  335. str(play_cnt) + "\n" +
  336. str(comment_cnt) + "\n" +
  337. str(like_cnt) + "\n" +
  338. str(share_cnt) + "\n" +
  339. str(video_width) + '*' + str(video_height) + "\n" +
  340. str(publish_time) + "\n" +
  341. str(user_name) + "\n" +
  342. str(avatar_url) + "\n" +
  343. str(video_url) + "\n" +
  344. str(cover_url) + "\n" +
  345. "zhihu_follow" + str(int(time.time())))
  346. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  347. our_video_id = Publish.upload_and_publish(log_type, env, our_uid)
  348. if env == 'dev':
  349. our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/" + str(
  350. our_video_id) + "/info"
  351. else:
  352. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
  353. Common.logger(log_type).info("视频上传完成:{}\n", video_title)
  354. Feishu.insert_columns(log_type, 'zhihu', '4MGuux', 'ROWS', 1, 2)
  355. time.sleep(1)
  356. upload_time = int(time.time())
  357. values = [[
  358. time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
  359. "定向榜",
  360. video_title,
  361. str(video_id),
  362. our_video_link,
  363. play_cnt,
  364. comment_cnt,
  365. like_cnt,
  366. share_cnt,
  367. voteup_cnt,
  368. int(duration),
  369. str(video_width) + '*' + str(video_height),
  370. time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(publish_time))),
  371. user_name,
  372. uid,
  373. 'https://www.zhihu.com/' + user_type + '/' + url_token,
  374. user_type,
  375. url_token,
  376. avatar_url,
  377. cover_url,
  378. video_url]]
  379. Feishu.update_values(log_type, 'zhihu', "4MGuux", "F2:Z2", values)
  380. Common.logger(log_type).info("视频已保存至云文档:{}\n", video_title)
  381. if is_end is True:
  382. Common.logger(log_type).info('到底了\n')
  383. cls.offset = 0
  384. return
  385. if __name__ == '__main__':
  386. ZhihuFollow.get_follow_feeds('follow', 'lindsayzou', 'https://www.zhihu.com/people/lindsayzou/zvideos', '6267140', 'dev')
  387. # ZhihuFollow.get_follow_feeds('follow', 'lao-ba-ping-ce', 'https://www.zhihu.com/org/lao-ba-ping-ce/zvideos', '6267140', 'dev')