feishu_lib.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/8/9
  4. import json
  5. import requests
  6. import urllib3
  7. from main.common import Common
  8. proxies = {"http": None, "https": None}
  9. class Feishu:
  10. """
  11. 编辑飞书云文档
  12. """
  13. # 看一看爬虫数据表
  14. kanyikan_url = "https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?"
  15. # 快手爬虫数据表
  16. kuaishou_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnICEfaw9llDNQkKgdymM1xf?"
  17. # 微视爬虫数据表
  18. weishi_url = "https://w42nne6hzg.feishu.cn/sheets/shtcn5YSWg91JfVGzj0SFZIRRPh?"
  19. # 小年糕爬虫数据表
  20. xiaoniangao_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?"
  21. # 音乐相册
  22. music_album = "https://w42nne6hzg.feishu.cn/sheets/shtcnT6zvmfsYe1g0iv4pt7855g?"
  23. # 本山祝福数据表
  24. crawler_benshanzhufu = "https://w42nne6hzg.feishu.cn/sheets/shtcnGh2rrsPYM4iVNEBO7OqWrb?"
  25. # 公众号爬虫表
  26. gzh_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnexNXnpDLHhARw0QdiwbYuA?"
  27. # 数据监控表
  28. crawler_monitor = "https://w42nne6hzg.feishu.cn/sheets/shtcnlZWYazInhf7Z60jkbLRJyd?"
  29. # 微群视频爬虫表
  30. crawler_weiqun_video = "https://w42nne6hzg.feishu.cn/sheets/shtcnoKThNquYRweaylMFVyo9Hc?"
  31. # 视频号爬虫表
  32. crawler_shipinhao = 'https://w42nne6hzg.feishu.cn/sheets/shtcn9rOdZRAGFbRkWpn7hqEHGc?'
  33. # 西瓜视频
  34. crawler_xigua = 'https://w42nne6hzg.feishu.cn/sheets/shtcnvOpx2P8vBXiV91Ot1MKIw8?'
  35. # 知乎 PC 端
  36. crawler_zhihu = 'https://w42nne6hzg.feishu.cn/sheets/shtcnkGPBmGsjaqapgzouuj8MXe?'
  37. # 吉祥幸福
  38. crawler_jixiangxingfu = 'https://w42nne6hzg.feishu.cn/sheets/shtcnSx4nafMbLTq7xl7RHBwHBf?'
  39. # 众妙音信
  40. crawler_zmyx = 'https://w42nne6hzg.feishu.cn/sheets/shtcnbZIxstPeM0xshW07b26sve?'
  41. # 岁岁年年迎福气
  42. crawler_ssnnyfq = 'https://w42nne6hzg.feishu.cn/sheets/shtcnyJmJSJynHDLLbLTkySfvZe?'
  43. # 祝福猫视频
  44. crawler_zhufumao = 'https://w42nne6hzg.feishu.cn/sheets/shtcnXfIJthvkjhI5zlEJq84i6g?'
  45. # 宗教公众号
  46. crawler_zongjiao = 'https://w42nne6hzg.feishu.cn/sheets/shtcn73NW0CyoOeF21HWO15KBsb?'
  47. # 好看视频
  48. crawler_haokan = 'https://w42nne6hzg.feishu.cn/sheets/shtcnaYz8Nhv8q6DbWtlL6rMEBd'
  49. # 看到就是福气
  50. crawler_kandaojiushifuqi = 'https://w42nne6hzg.feishu.cn/sheets/shtcnEokBkIjOUPAk8vbbPKnXgb'
  51. # 胜胜影音
  52. crawler_shengshengyingyin = 'https://w42nne6hzg.feishu.cn/sheets/shtcnz1ymxHL1u8WHblfqfys7qe'
  53. # 刚刚都传
  54. crawler_ganggangdouchuan = 'https://w42nne6hzg.feishu.cn/sheets/shtcnTuJgeZU2bc7VaesAqk3QJx'
  55. # 飞书路径token
  56. @classmethod
  57. def spreadsheettoken(cls, crawler):
  58. """
  59. :param crawler: 哪个爬虫
  60. """
  61. if crawler == "kanyikan":
  62. return "shtcngRPoDYAi24x52j2nDuHMih"
  63. elif crawler == "kuaishou":
  64. return "shtcnICEfaw9llDNQkKgdymM1xf"
  65. elif crawler == "weishi":
  66. return "shtcn5YSWg91JfVGzj0SFZIRRPh"
  67. elif crawler == "xiaoniangao":
  68. return "shtcnYxiyQ1wLklo1W5Kdqc9cGh"
  69. elif crawler == "monitor":
  70. return "shtcnlZWYazInhf7Z60jkbLRJyd"
  71. elif crawler == "music_album":
  72. return "shtcnT6zvmfsYe1g0iv4pt7855g"
  73. elif crawler == "bszf":
  74. return "shtcnGh2rrsPYM4iVNEBO7OqWrb"
  75. elif crawler == "gzh":
  76. return "shtcnexNXnpDLHhARw0QdiwbYuA"
  77. elif crawler == "weiqun":
  78. return "shtcnoKThNquYRweaylMFVyo9Hc"
  79. elif crawler == 'shipinhao':
  80. return 'shtcn9rOdZRAGFbRkWpn7hqEHGc'
  81. elif crawler == 'xigua':
  82. return 'shtcnvOpx2P8vBXiV91Ot1MKIw8'
  83. elif crawler == 'zhihu':
  84. return 'shtcnkGPBmGsjaqapgzouuj8MXe'
  85. elif crawler == 'jxxf':
  86. return 'shtcnSx4nafMbLTq7xl7RHBwHBf'
  87. elif crawler == 'zmyx':
  88. return 'shtcnbZIxstPeM0xshW07b26sve'
  89. elif crawler == 'ssnnyfq':
  90. return 'shtcnyJmJSJynHDLLbLTkySfvZe'
  91. elif crawler == 'zhufumao':
  92. return 'shtcnXfIJthvkjhI5zlEJq84i6g'
  93. elif crawler == 'zongjiao':
  94. return 'shtcn73NW0CyoOeF21HWO15KBsb'
  95. elif crawler == 'haokan':
  96. return 'shtcnaYz8Nhv8q6DbWtlL6rMEBd'
  97. elif crawler == 'kdjsfq':
  98. return 'shtcnEokBkIjOUPAk8vbbPKnXgb'
  99. elif crawler == 'ssyy':
  100. return 'shtcnz1ymxHL1u8WHblfqfys7qe'
  101. elif crawler == 'ggdc':
  102. return 'shtcnTuJgeZU2bc7VaesAqk3QJx'
  103. # 获取飞书api token
  104. @classmethod
  105. def get_token(cls, log_type):
  106. """
  107. 获取飞书api token
  108. :return:
  109. """
  110. url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal/"
  111. post_data = {"app_id": "cli_a13ad2afa438d00b", # 这里账号密码是发布应用的后台账号及密码
  112. "app_secret": "4tK9LY9VbiQlY5umhE42dclBFo6t4p5O"}
  113. try:
  114. urllib3.disable_warnings()
  115. response = requests.post(url=url, data=post_data, proxies=proxies, verify=False)
  116. tenant_access_token = response.json()["tenant_access_token"]
  117. return tenant_access_token
  118. except Exception as e:
  119. Common.logger(log_type).error("获取飞书 api token 异常:{}", e)
  120. # 获取表格元数据
  121. @classmethod
  122. def get_metainfo(cls, log_type, crawler):
  123. """
  124. 获取表格元数据
  125. :return:
  126. """
  127. get_metainfo_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \
  128. + cls.spreadsheettoken(crawler) + "/metainfo"
  129. headers = {
  130. "Authorization": "Bearer " + cls.get_token(log_type),
  131. "Content-Type": "application/json; charset=utf-8"
  132. }
  133. params = {
  134. "extFields": "protectedRange", # 额外返回的字段,extFields=protectedRange时返回保护行列信息
  135. "user_id_type": "open_id" # 返回的用户id类型,可选open_id,union_id
  136. }
  137. try:
  138. urllib3.disable_warnings()
  139. r = requests.get(url=get_metainfo_url, headers=headers, params=params, proxies=proxies, verify=False)
  140. response = json.loads(r.content.decode("utf8"))
  141. return response
  142. except Exception as e:
  143. Common.logger(log_type).error("获取表格元数据异常:{}", e)
  144. # 读取工作表中所有数据
  145. @classmethod
  146. def get_values_batch(cls, log_type, crawler, sheetid):
  147. """
  148. 读取工作表中所有数据
  149. :param log_type: 启用哪个 log
  150. :param crawler: 哪个爬虫
  151. :param sheetid: 哪张表
  152. :return: 所有数据
  153. """
  154. get_values_batch_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \
  155. + cls.spreadsheettoken(crawler) + "/values_batch_get"
  156. headers = {
  157. "Authorization": "Bearer " + cls.get_token(log_type),
  158. "Content-Type": "application/json; charset=utf-8"
  159. }
  160. params = {
  161. # 多个查询范围 如 url?ranges=range1,range2 ,其中 range 包含 sheetId 与单元格范围两部分
  162. "ranges": sheetid,
  163. # valueRenderOption=ToString 可返回纯文本的值(数值类型除外);
  164. # valueRenderOption=FormattedValue 计算并格式化单元格;
  165. # valueRenderOption=Formula单元格中含有公式时返回公式本身;
  166. # valueRenderOption=UnformattedValue计算但不对单元格进行格式化
  167. "valueRenderOption": "ToString",
  168. # dateTimeRenderOption=FormattedString 计算并将时间日期按照其格式进行格式化,但不会对数字进行格式化,返回格式化后的字符串。
  169. "dateTimeRenderOption": "",
  170. # 返回的用户id类型,可选open_id,union_id
  171. "user_id_type": "open_id"
  172. }
  173. try:
  174. urllib3.disable_warnings()
  175. r = requests.get(url=get_values_batch_url, headers=headers, params=params, proxies=proxies, verify=False)
  176. # print(r.text)
  177. response = json.loads(r.content.decode("utf8"))
  178. values = response["data"]["valueRanges"][0]["values"]
  179. return values
  180. except Exception as e:
  181. Common.logger(log_type).error("读取工作表所有数据异常:{}", e)
  182. # 工作表,插入行或列
  183. @classmethod
  184. def insert_columns(cls, log_type, crawler, sheetid, majordimension, startindex, endindex):
  185. """
  186. 工作表插入行或列
  187. :param log_type: 日志路径
  188. :param crawler: 哪个爬虫的云文档
  189. :param sheetid:哪张工作表
  190. :param majordimension:行或者列, ROWS、COLUMNS
  191. :param startindex:开始位置
  192. :param endindex:结束位置
  193. """
  194. insert_columns_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \
  195. + cls.spreadsheettoken(crawler) + "/insert_dimension_range"
  196. headers = {
  197. "Authorization": "Bearer " + cls.get_token(log_type),
  198. "Content-Type": "application/json; charset=utf-8"
  199. }
  200. body = {
  201. "dimension": {
  202. "sheetId": sheetid,
  203. "majorDimension": majordimension, # 默认 ROWS ,可选 ROWS、COLUMNS
  204. "startIndex": startindex, # 开始的位置
  205. "endIndex": endindex # 结束的位置
  206. },
  207. "inheritStyle": "AFTER" # BEFORE 或 AFTER,不填为不继承 style
  208. }
  209. try:
  210. urllib3.disable_warnings()
  211. r = requests.post(url=insert_columns_url, headers=headers, json=body, proxies=proxies, verify=False)
  212. Common.logger(log_type).info("插入行或列:{}", r.json()["msg"])
  213. except Exception as e:
  214. Common.logger(log_type).error("插入行或列异常:{}", e)
  215. # 写入数据
  216. @classmethod
  217. def update_values(cls, log_type, crawler, sheetid, ranges, values):
  218. """
  219. 写入数据
  220. :param log_type: 日志路径
  221. :param crawler: 哪个爬虫的云文档
  222. :param sheetid:哪张工作表
  223. :param ranges:单元格范围
  224. :param values:写入的具体数据,list
  225. """
  226. update_values_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \
  227. + cls.spreadsheettoken(crawler) + "/values_batch_update"
  228. headers = {
  229. "Authorization": "Bearer " + cls.get_token(log_type),
  230. "Content-Type": "application/json; charset=utf-8"
  231. }
  232. body = {
  233. "valueRanges": [
  234. {
  235. "range": sheetid + "!" + ranges,
  236. "values": values
  237. },
  238. ],
  239. }
  240. try:
  241. urllib3.disable_warnings()
  242. r = requests.post(url=update_values_url, headers=headers, json=body, proxies=proxies, verify=False)
  243. Common.logger(log_type).info("写入数据:{}", r.json()["msg"])
  244. except Exception as e:
  245. Common.logger(log_type).error("写入数据异常:{}", e)
  246. # 合并单元格
  247. @classmethod
  248. def merge_cells(cls, log_type, crawler, sheetid, ranges):
  249. """
  250. 合并单元格
  251. :param log_type: 日志路径
  252. :param crawler: 哪个爬虫
  253. :param sheetid:哪张工作表
  254. :param ranges:需要合并的单元格范围
  255. """
  256. merge_cells_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \
  257. + cls.spreadsheettoken(crawler) + "/merge_cells"
  258. headers = {
  259. "Authorization": "Bearer " + cls.get_token(log_type),
  260. "Content-Type": "application/json; charset=utf-8"
  261. }
  262. body = {
  263. "range": sheetid + "!" + ranges,
  264. "mergeType": "MERGE_ROWS"
  265. }
  266. try:
  267. urllib3.disable_warnings()
  268. r = requests.post(url=merge_cells_url, headers=headers, json=body, proxies=proxies, verify=False)
  269. Common.logger(log_type).info("合并单元格:{}", r.json()["msg"])
  270. except Exception as e:
  271. Common.logger(log_type).error("合并单元格异常:{}", e)
  272. # 读取单元格数据
  273. @classmethod
  274. def get_range_value(cls, log_type, crawler, sheetid, cell):
  275. """
  276. 读取单元格内容
  277. :param log_type: 日志路径
  278. :param crawler: 哪个爬虫
  279. :param sheetid: 哪张工作表
  280. :param cell: 哪个单元格
  281. :return: 单元格内容
  282. """
  283. get_range_value_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \
  284. + cls.spreadsheettoken(crawler) + "/values/" + sheetid + "!" + cell
  285. headers = {
  286. "Authorization": "Bearer " + cls.get_token(log_type),
  287. "Content-Type": "application/json; charset=utf-8"
  288. }
  289. params = {
  290. # valueRenderOption=ToString 可返回纯文本的值(数值类型除外);
  291. # valueRenderOption=FormattedValue 计算并格式化单元格;
  292. # valueRenderOption=Formula 单元格中含有公式时返回公式本身;
  293. # valueRenderOption=UnformattedValue 计算但不对单元格进行格式化。
  294. "valueRenderOption": "FormattedValue",
  295. # dateTimeRenderOption=FormattedString 计算并对时间日期按照其格式进行格式化,但不会对数字进行格式化,返回格式化后的字符串。
  296. "dateTimeRenderOption": "",
  297. # 返回的用户id类型,可选open_id,union_id
  298. "user_id_type": "open_id"
  299. }
  300. try:
  301. urllib3.disable_warnings()
  302. r = requests.get(url=get_range_value_url, headers=headers, params=params, proxies=proxies, verify=False)
  303. # print(r.text)
  304. return r.json()["data"]["valueRange"]["values"][0]
  305. except Exception as e:
  306. Common.logger(log_type).error("读取单元格数据异常:{}", e)
  307. # 删除行或列,可选 ROWS、COLUMNS
  308. @classmethod
  309. def dimension_range(cls, log_type, crawler, sheetid, major_dimension, startindex, endindex):
  310. """
  311. 删除行或列
  312. :param log_type: 日志路径
  313. :param crawler: 哪个爬虫
  314. :param sheetid:工作表
  315. :param major_dimension:默认 ROWS ,可选 ROWS、COLUMNS
  316. :param startindex:开始的位置
  317. :param endindex:结束的位置
  318. :return:
  319. """
  320. dimension_range_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \
  321. + cls.spreadsheettoken(crawler) + "/dimension_range"
  322. headers = {
  323. "Authorization": "Bearer " + cls.get_token(log_type),
  324. "Content-Type": "application/json; charset=utf-8"
  325. }
  326. body = {
  327. "dimension": {
  328. "sheetId": sheetid,
  329. "majorDimension": major_dimension,
  330. "startIndex": startindex,
  331. "endIndex": endindex
  332. }
  333. }
  334. try:
  335. urllib3.disable_warnings()
  336. r = requests.delete(url=dimension_range_url, headers=headers, json=body, proxies=proxies, verify=False)
  337. Common.logger(log_type).info("删除视频数据:{}", r.json()["msg"])
  338. except Exception as e:
  339. Common.logger(log_type).error(f"删除视频数据异常:{e}\n")
  340. # 获取用户 ID
  341. @classmethod
  342. def get_userid(cls, log_type, username):
  343. try:
  344. url = "https://open.feishu.cn/open-apis/user/v1/batch_get_id?"
  345. headers = {
  346. "Authorization": "Bearer " + cls.get_token(log_type),
  347. "Content-Type": "application/json; charset=utf-8"
  348. }
  349. # 手机号
  350. wangkun = "13426262515"
  351. gaonannan = "18501180073"
  352. xinxin = "15546206651"
  353. huxinxue = "18832292015"
  354. wuchaoyue = "15712941385"
  355. lijinchao = '18524120540'
  356. if username == "wangkun":
  357. username = wangkun
  358. elif username == "gaonannan":
  359. username = gaonannan
  360. elif username == "xinxin":
  361. username = xinxin
  362. elif username == "huxinxue":
  363. username = huxinxue
  364. elif username == "wuchaoyue":
  365. username = wuchaoyue
  366. elif username == "lijinchao":
  367. username = lijinchao
  368. data = {"mobiles": [username]}
  369. urllib3.disable_warnings()
  370. r = requests.get(url=url, headers=headers, params=data, verify=False, proxies=proxies)
  371. open_id = r.json()["data"]["mobile_users"][username][0]["open_id"]
  372. Common.logger(log_type).info(f"{username}:{open_id}")
  373. # print(f"{username}:{open_id}")
  374. return open_id
  375. except Exception as e:
  376. Common.logger(log_type).error(f"get_userid异常:{e}\n")
  377. # 飞书机器人
  378. @classmethod
  379. def bot(cls, log_type, crawler, text):
  380. try:
  381. url = "https://open.feishu.cn/open-apis/bot/v2/hook/96989577-50e7-4653-9ec2-308fe3f2c5fe"
  382. headers = {
  383. 'Content-Type': 'application/json'
  384. }
  385. if crawler == "kanyikan":
  386. content = "看一看爬虫表"
  387. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih"
  388. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  389. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  390. elif crawler == "xiaoniangao_hour":
  391. content = "小年糕_小时级_已下载表"
  392. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2"
  393. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  394. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  395. elif crawler == "xiaoniangao_person":
  396. content = "小年糕_用户主页_已下载表"
  397. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=Wu0CeL"
  398. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  399. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  400. elif crawler == "xiaoniangao_play":
  401. content = "小年糕_播放量_已下载表"
  402. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=c85k1C"
  403. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  404. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  405. elif crawler == 'xigua_video':
  406. content = '西瓜视频_用户主页_已下载表'
  407. sheet_url = 'https://w42nne6hzg.feishu.cn/sheets/shtcnvOpx2P8vBXiV91Ot1MKIw8?sheet=e075e9'
  408. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  409. cls.get_userid(log_type, "wuchaoyue")) + "></at>\n"
  410. elif crawler == 'xigua_little_video':
  411. content = '西瓜视频_小视频_已下载表'
  412. sheet_url = 'https://w42nne6hzg.feishu.cn/sheets/shtcnvOpx2P8vBXiV91Ot1MKIw8?sheet=hDSDnv'
  413. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  414. cls.get_userid(log_type, "wuchaoyue")) + "></at>\n"
  415. elif crawler == 'zhihu_hot':
  416. content = '知乎_热门_已下载表'
  417. sheet_url = 'https://w42nne6hzg.feishu.cn/sheets/shtcnkGPBmGsjaqapgzouuj8MXe?sheet=8871e3'
  418. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  419. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  420. elif crawler == 'zhihu_follow':
  421. content = '知乎_定向_已下载表'
  422. sheet_url = 'https://w42nne6hzg.feishu.cn/sheets/shtcnkGPBmGsjaqapgzouuj8MXe?sheet=4MGuux'
  423. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  424. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  425. elif crawler == 'haokan_hot':
  426. content = '好看_热榜_已下载表'
  427. sheet_url = 'https://w42nne6hzg.feishu.cn/sheets/shtcnaYz8Nhv8q6DbWtlL6rMEBd?sheet=5pWipX'
  428. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  429. cls.get_userid(log_type, "wuchaoyue")) + "></at>\n"
  430. elif crawler == 'haokan_channel':
  431. content = '好看_频道_已下载表'
  432. sheet_url = 'https://w42nne6hzg.feishu.cn/sheets/shtcnaYz8Nhv8q6DbWtlL6rMEBd?sheet=7f05d8'
  433. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  434. cls.get_userid(log_type, "wuchaoyue")) + "></at>\n"
  435. elif crawler == 'haokan_follow':
  436. content = '好看_定向_已下载表'
  437. sheet_url = 'https://w42nne6hzg.feishu.cn/sheets/shtcnaYz8Nhv8q6DbWtlL6rMEBd?sheet=kVaSjf'
  438. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  439. cls.get_userid(log_type, "wuchaoyue")) + "></at>\n"
  440. elif crawler == "music_album":
  441. content = "音乐相册爬虫表"
  442. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnT6zvmfsYe1g0iv4pt7855g"
  443. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  444. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  445. elif crawler == "ssyy":
  446. content = "胜胜影音爬虫表"
  447. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnz1ymxHL1u8WHblfqfys7qe"
  448. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  449. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  450. elif crawler == "ggdc":
  451. content = "刚刚都传爬虫表"
  452. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnTuJgeZU2bc7VaesAqk3QJx"
  453. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  454. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  455. elif crawler == "bszf":
  456. content = "本山祝福爬虫表"
  457. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnGh2rrsPYM4iVNEBO7OqWrb"
  458. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  459. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  460. elif crawler == "jxxf":
  461. content = "吉祥幸福爬虫表"
  462. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnSx4nafMbLTq7xl7RHBwHBf"
  463. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  464. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  465. elif crawler == "zmyx":
  466. content = "众妙音信爬虫表"
  467. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnbZIxstPeM0xshW07b26sve"
  468. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  469. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  470. elif crawler == "zhufumao":
  471. content = "祝福猫视频爬虫表"
  472. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnXfIJthvkjhI5zlEJq84i6g"
  473. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  474. cls.get_userid(log_type, "gaonannan")) + "></at>\n"
  475. elif crawler == "kuaishou_follow":
  476. content = "快手_用户主页_已下载表"
  477. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnICEfaw9llDNQkKgdymM1xf?sheet=fYdA8F"
  478. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  479. cls.get_userid(log_type, "xinxin")) + "></at>\n"
  480. elif crawler == "kuaishou_recommend":
  481. content = "快手_推荐榜_已下载表"
  482. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnICEfaw9llDNQkKgdymM1xf?sheet=3cd128"
  483. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  484. cls.get_userid(log_type, "xinxin")) + "></at>\n"
  485. elif crawler == "ssnnyfq":
  486. content = "岁岁年年迎福气_已下载表"
  487. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnyJmJSJynHDLLbLTkySfvZe?sheet=290bae"
  488. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  489. cls.get_userid(log_type, "xinxin")) + "></at>\n"
  490. elif crawler == "kdjsfq":
  491. content = "看到就是福气_已下载表"
  492. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnEokBkIjOUPAk8vbbPKnXgb?sheet=ad3b6d"
  493. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  494. cls.get_userid(log_type, "xinxin")) + "></at>\n"
  495. elif crawler == "gzh":
  496. content = "公众号爬虫表"
  497. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnexNXnpDLHhARw0QdiwbYuA"
  498. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  499. cls.get_userid(log_type, "huxinxue")) + "></at>\n"
  500. elif crawler == "weiqun":
  501. content = "微群爬虫表"
  502. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnoKThNquYRweaylMFVyo9Hc"
  503. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  504. cls.get_userid(log_type, "xinxin")) + "></at>\n"
  505. elif crawler == "weishi":
  506. content = "微视爬虫表"
  507. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcn5YSWg91JfVGzj0SFZIRRPh"
  508. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  509. cls.get_userid(log_type, "xinxin")) + "></at>\n"
  510. elif crawler == "shipinhao_recommend":
  511. content = "视频号_推荐_已下载表"
  512. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcn9rOdZRAGFbRkWpn7hqEHGc?sheet=c77cf9"
  513. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  514. cls.get_userid(log_type, "wuchaoyue")) + "></at>\n"
  515. elif crawler == "shipinhao_follow":
  516. content = "视频号_定向_已下载表"
  517. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcn9rOdZRAGFbRkWpn7hqEHGc?sheet=KsVtLe"
  518. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  519. cls.get_userid(log_type, "wuchaoyue")) + "></at>\n"
  520. elif crawler == "zongjiao":
  521. content = "宗教公众号爬虫表"
  522. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcn73NW0CyoOeF21HWO15KBsb"
  523. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at> <at id=" + str(
  524. cls.get_userid(log_type, "huxinxue")) + "></at>\n"
  525. else:
  526. content = "小年糕爬虫表"
  527. sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh"
  528. users = "\n<at id=" + str(cls.get_userid(log_type, "wangkun")) + "></at>\n"
  529. data = json.dumps({
  530. "msg_type": "interactive",
  531. "card": {
  532. "config": {
  533. "wide_screen_mode": True,
  534. "enable_forward": True
  535. },
  536. "elements": [{
  537. "tag": "div",
  538. "text": {
  539. "content": users + text,
  540. "tag": "lark_md"
  541. }
  542. }, {
  543. "actions": [{
  544. "tag": "button",
  545. "text": {
  546. "content": content,
  547. "tag": "lark_md"
  548. },
  549. "url": sheet_url,
  550. "type": "default",
  551. "value": {}
  552. }],
  553. "tag": "action"
  554. }],
  555. "header": {
  556. "title": {
  557. "content": "📣您有新的报警,请注意查收",
  558. "tag": "plain_text"
  559. }
  560. }
  561. }
  562. })
  563. urllib3.disable_warnings()
  564. r = requests.post(url, headers=headers, data=data, verify=False, proxies=proxies)
  565. Common.logger(log_type).info(f'触发机器人消息:{r}, {r.json()["StatusMessage"]}')
  566. except Exception as e:
  567. Common.logger(log_type).error(f"bot异常:{e}\n")
  568. if __name__ == "__main__":
  569. Feishu.bot("bot", "ggdc", "别紧张,还是我,测试一下")
  570. # print(Feishu.get_userid("shipinhao", "lijinchao"))
  571. pass