# -*- coding: utf-8 -*- # @Author: wangkun # @Time: 2022/5/27 import json import time import requests import urllib3 from common import Common proxies = {"http": None, "https": None} class Feishu: """ 编辑飞书云文档 """ # 看一看爬虫数据表 kanyikan_url = "https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?" # 快手爬虫数据表 kuaishou_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnp4SaJt37q6OOOrYzPMjQkg?" # 微视爬虫数据表 weishi_url = "https://w42nne6hzg.feishu.cn/sheets/shtcn5YSWg91JfVGzj0SFZIRRPh?" # 小年糕爬虫数据表 xiaoniangao_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?" # twitter 爬虫吧 twitter_url = "https://whtlrai9ej.feishu.cn/sheets/shtcn6BYfYuqegIP13ORB6rI2dh?" # 飞书路径token @classmethod def spreadsheettoken(cls, crawler): """ :param crawler: 哪个爬虫 """ if crawler == "kanyikan": return "shtcngRPoDYAi24x52j2nDuHMih" elif crawler == "kuaishou": return "shtcnp4SaJt37q6OOOrYzPMjQkg" elif crawler == "weishi": return "shtcn5YSWg91JfVGzj0SFZIRRPh" elif crawler == "xiaoniangao": return "shtcnYxiyQ1wLklo1W5Kdqc9cGh" elif crawler == "twitter": return "shtcn6BYfYuqegIP13ORB6rI2dh" # 获取飞书api token @classmethod def get_token(cls): """ 获取飞书api token :return: """ time.sleep(1) url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal/" post_data = {"app_id": "cli_a13ad2afa438d00b", # 这里账号密码是发布应用的后台账号及密码 "app_secret": "4tK9LY9VbiQlY5umhE42dclBFo6t4p5O"} try: urllib3.disable_warnings() response = requests.post(url=url, data=post_data, proxies=proxies, verify=False) tenant_access_token = response.json()["tenant_access_token"] return tenant_access_token except Exception as e: Common.logger().error("获取飞书 api token 异常:{}", e) # 获取表格元数据 @classmethod def get_metainfo(cls, crawler): """ 获取表格元数据 :return: """ get_metainfo_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \ + cls.spreadsheettoken(crawler) + "/metainfo" headers = { "Authorization": "Bearer " + cls.get_token(), "Content-Type": "application/json; charset=utf-8" } params = { "extFields": "protectedRange", # 额外返回的字段,extFields=protectedRange时返回保护行列信息 "user_id_type": "open_id" # 返回的用户id类型,可选open_id,union_id } try: urllib3.disable_warnings() r = requests.get(url=get_metainfo_url, headers=headers, params=params, proxies=proxies, verify=False) response = json.loads(r.content.decode("utf8")) return response except Exception as e: Common.logger().error("获取表格元数据异常:{}", e) # 读取工作表中所有数据 @classmethod def get_values_batch(cls, crawler, sheetid): """ 读取工作表中所有数据 :param crawler: 哪个爬虫 :param sheetid: 哪张表 :return: 所有数据 """ get_values_batch_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \ + cls.spreadsheettoken(crawler) + "/values_batch_get" headers = { "Authorization": "Bearer " + cls.get_token(), "Content-Type": "application/json; charset=utf-8" } params = { # 多个查询范围 如 url?ranges=range1,range2 ,其中 range 包含 sheetId 与单元格范围两部分 "ranges": sheetid, # valueRenderOption=ToString 可返回纯文本的值(数值类型除外); # valueRenderOption=FormattedValue 计算并格式化单元格; # valueRenderOption=Formula单元格中含有公式时返回公式本身; # valueRenderOption=UnformattedValue计算但不对单元格进行格式化 "valueRenderOption": "ToString", # dateTimeRenderOption=FormattedString 计算并将时间日期按照其格式进行格式化,但不会对数字进行格式化,返回格式化后的字符串。 "dateTimeRenderOption": "", # 返回的用户id类型,可选open_id,union_id "user_id_type": "open_id" } try: urllib3.disable_warnings() r = requests.get(url=get_values_batch_url, headers=headers, params=params, proxies=proxies, verify=False) response = json.loads(r.content.decode("utf8")) values = response["data"]["valueRanges"][0]["values"] return values except Exception as e: Common.logger().error("读取工作表所有数据异常:{}", e) # 工作表,插入行或列 @classmethod def insert_columns(cls, crawler, sheetid, majordimension, startindex, endindex): """ 工作表插入行或列 :param crawler: 哪个爬虫 :param sheetid:哪张工作表 :param majordimension:行或者列 :param startindex:开始位置 :param endindex:结束位置 """ insert_columns_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \ + cls.spreadsheettoken(crawler) + "/insert_dimension_range" headers = { "Authorization": "Bearer " + cls.get_token(), "Content-Type": "application/json; charset=utf-8" } body = { "dimension": { "sheetId": sheetid, "majorDimension": majordimension, # 默认 ROWS ,可选 ROWS、COLUMNS "startIndex": startindex, # 开始的位置 "endIndex": endindex # 结束的位置 }, "inheritStyle": "AFTER" # BEFORE 或 AFTER,不填为不继承 style } try: urllib3.disable_warnings() r = requests.post(url=insert_columns_url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("插入行或列:{}", r.json()["msg"]) except Exception as e: Common.logger().error("插入行或列异常:{}", e) # 写入数据 @classmethod def update_values(cls, crawler, sheetid, ranges, values): """ 写入数据 :param crawler: 哪个爬虫 :param sheetid:哪张工作表 :param ranges:单元格范围 :param values:写入的具体数据,list """ update_values_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \ + cls.spreadsheettoken(crawler) + "/values_batch_update" headers = { "Authorization": "Bearer " + cls.get_token(), "Content-Type": "application/json; charset=utf-8" } body = { "valueRanges": [ { "range": sheetid + "!" + ranges, "values": values }, ], } try: urllib3.disable_warnings() r = requests.post(url=update_values_url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("写入数据:{}", r.json()["msg"]) except Exception as e: Common.logger().error("写入数据异常:{}", e) # 合并单元格 @classmethod def merge_cells(cls, crawler, sheetid, ranges): """ 合并单元格 :param crawler: 哪个爬虫 :param sheetid:哪张工作表 :param ranges:需要合并的单元格范围 """ merge_cells_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \ + cls.spreadsheettoken(crawler) + "/merge_cells" headers = { "Authorization": "Bearer " + cls.get_token(), "Content-Type": "application/json; charset=utf-8" } body = { "range": sheetid + "!" + ranges, "mergeType": "MERGE_ROWS" } try: urllib3.disable_warnings() r = requests.post(url=merge_cells_url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("合并单元格:{}", r.json()["msg"]) except Exception as e: Common.logger().error("合并单元格异常:{}", e) # 读取单元格数据 @classmethod def get_range_value(cls, crawler, sheetid, cell): """ 读取单元格内容 :param crawler: 哪个爬虫 :param sheetid: 哪张工作表 :param cell: 哪个单元格 :return: 单元格内容 """ get_range_value_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \ + cls.spreadsheettoken(crawler) + "/values/" + sheetid + "!" + cell headers = { "Authorization": "Bearer " + cls.get_token(), "Content-Type": "application/json; charset=utf-8" } params = { # valueRenderOption=ToString 可返回纯文本的值(数值类型除外); # valueRenderOption=FormattedValue 计算并格式化单元格; # valueRenderOption=Formula 单元格中含有公式时返回公式本身; # valueRenderOption=UnformattedValue 计算但不对单元格进行格式化。 "valueRenderOption": "FormattedValue", # dateTimeRenderOption=FormattedString 计算并对时间日期按照其格式进行格式化,但不会对数字进行格式化,返回格式化后的字符串。 "dateTimeRenderOption": "", # 返回的用户id类型,可选open_id,union_id "user_id_type": "open_id" } try: urllib3.disable_warnings() r = requests.get(url=get_range_value_url, headers=headers, params=params, proxies=proxies, verify=False) return r.json()["data"]["valueRange"]["values"][0] except Exception as e: Common.logger().error("读取单元格数据异常:{}", e) # 删除行或列,可选 ROWS、COLUMNS @classmethod def dimension_range(cls, crawler, sheetid, major_dimension, startindex, endindex): """ 删除行或列 :param crawler: 哪个爬虫 :param sheetid:工作表 :param major_dimension:默认 ROWS ,可选 ROWS、COLUMNS :param startindex:开始的位置 :param endindex:结束的位置 :return: """ dimension_range_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/" \ + cls.spreadsheettoken(crawler) + "/dimension_range" headers = { "Authorization": "Bearer " + cls.get_token(), "Content-Type": "application/json; charset=utf-8" } body = { "dimension": { "sheetId": sheetid, "majorDimension": major_dimension, "startIndex": startindex, "endIndex": endindex } } try: urllib3.disable_warnings() r = requests.delete(url=dimension_range_url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("删除视频数据:{}", r.json()["msg"]) except Exception as e: Common.logger().error("删除视频数据异常:{}", e) # 查找单元格 @classmethod def find_cell(cls, crawler, sheetid, find_text): """ 查找单元格 :param crawler: 哪个爬虫 :param sheetid: 哪张表 # :param ranges: 单元格范围 :param find_text: 查找的字符 :return: 返回单元格索引 """ find_cell_url = "https://open.feishu.cn/open-apis/sheets/v3/spreadsheets/" \ + cls.spreadsheettoken(crawler) + "/sheets/" \ + sheetid + "/find" headers = { "Authorization": "Bearer " + cls.get_token(), "Content-Type": "application/json; charset=utf-8" } rows_count = len(cls.get_values_batch("twitter", "db114c")) body = { "find_condition": { "range": sheetid + "!A1:A" + str(rows_count), "match_case": True, # 是否忽略大小写 "match_entire_cell": False, # 是否匹配整个单元格 "search_by_regex": False, # 是否为正则匹配 "include_formulas": False # 是否搜索公式内容 }, "find": find_text # 搜索内容 } try: urllib3.disable_warnings() r = requests.post(url=find_cell_url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("查找单元格:{}", r.json()["msg"]) matched_cell = r.json()["data"]["find_result"]["matched_cells"][0].split("A")[-1] return matched_cell except Exception as e: Common.logger().error("查找单元格异常:{}", e) # 筛选:filter @classmethod def filter_created_at(cls): filter_created_at_url = "https://open.feishu.cn/open-apis/sheets/v3/spreadsheets/" \ "shtcn8fFzDhCFHpB6vzf51s2xbf/sheets/48cfb0/filter" headers = { "Authorization": "Bearer " + cls.get_token(), "Content-Type": "application/json; charset=utf-8" } body = { "col": "A", "condition": { "filter_type": "number", "compare_type": "less", "expected": [ "6" ] } } try: urllib3.disable_warnings() r = requests.put(url=filter_created_at_url, headers=headers, json=body, proxies=proxies, verify=False) print(r.json()) except Exception as e: Common.logger().error("查找单元格异常:{}", e) class Bitable: """ 多维表格 API 文档地址:https://w42nne6hzg.feishu.cn/base/bascnpAYvIA0B1hBtNJlriZceUV?table=tblqMbXrpqFbDLNE&view=vewsMtek0O app_token:bascnpAYvIA0B1hBtNJlriZceUV """ app_token = "bascnpAYvIA0B1hBtNJlriZceUV" table_id = "tblqMbXrpqFbDLNE" page_token = "" # 列出记录时,翻页参数 # 获取飞书api token @classmethod def tenant_access_token(cls): """ 获取飞书api token :return: """ time.sleep(1) url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal/" post_data = {"app_id": "cli_a13ad2afa438d00b", # 这里账号密码是发布应用的后台账号及密码 "app_secret": "4tK9LY9VbiQlY5umhE42dclBFo6t4p5O"} try: urllib3.disable_warnings() response = requests.post(url=url, data=post_data, proxies=proxies, verify=False) tenant_access_token = response.json()["tenant_access_token"] return tenant_access_token except Exception as e: Common.logger().error("获取tenant_access_token异常:{}", e) # 获取多维表格元数据 @classmethod def get_apps(cls): """ 获取多维表格元数据 该接口支持调用频率上限为 20 QPS https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app/get """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" + cls.app_token headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } try: urllib3.disable_warnings() r = requests.get(url=url, headers=headers, proxies=proxies, verify=False) Common.logger().info("获取多维表格元数据,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("获取多维表格元数据异常:{}", e) # 列出数据表 @classmethod def get_tables(cls): """ 列出数据表 该接口支持调用频率上限为 20 QPS https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table/list """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" + cls.app_token + "/tables" headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } params = { "page_token": "", "page_size": "" } try: urllib3.disable_warnings() r = requests.get(url=url, headers=headers, params=params, proxies=proxies, verify=False) Common.logger().info("列出数据表,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("列出数据表异常:{}", e) # 列出记录 @classmethod def list_records(cls, count): """ 该接口用于列出数据表中的现有记录,单次最多列出 100 行记录,支持分页获取。 该接口支持调用频率上限为 1000 次/分钟 https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table-record/list """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" \ + cls.app_token + "/tables/" + cls.table_id + "/records" headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } params = { "view_id": "", # 视图 id; 注意: # 如 filter 或 sort 有值,view_id 会被忽略。 # 示例值: "vewqhz51lk" "filter": "", # 筛选参数; 注意: # 1.筛选记录的表达式不超过2000个字符。 # 2.不支持对“人员”以及“关联字段”的属性进行过滤筛选,如人员的 OpenID。 # 3.仅支持字段在页面展示字符值进行筛选。 # 详细参考:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/filter # 示例值:"示例表达式:AND(CurrentValue.[身高]>180, CurrentValue.[体重]>150)" "sort": "", # 排序参数。注意: # 1.表达式需要不超过1000字符。 # 2.不支持对带“公式”和“关联字段”的表的使用。 # 示例值:"["字段1 DESC","字段2 ASC"] # 注意:使用引号将字段名称和顺序逆序连接起来。" "field_names": "[]", # 字段名称。示例值:"["字段1"]" "text_field_as_array": True, # 控制多行文本字段数据的返回格式,true 表示以数组形式返回。注意: # 1.多行文本中如果有超链接部分,则会返回链接的 URL。 # 2.目前可以返回多行文本中 URL 类型为多维表格链接、飞书 doc、飞书 sheet的URL类型以及@人员的数据结构。 # 示例值:true # "user_id_type": "", # 用户 ID 类型 # 示例值:"open_id" # 可选值有: # open_id:用户的 open id # union_id:用户的 union id # user_id:用户的 user id # 默认值:open_id "display_formula_ref": "", # 控制公式、查找引用是否显示完整的原样返回结果。示例值:true "automatic_fields": "", # 控制是否返回自动计算的字段 # 例如 created_by/created_time/last_modified_by/last_modified_time,true 表示返回 # 示例值:true "page_token": "", # 分页标记 # 第一次请求不填,表示从头开始遍历; # 分页查询结果还有更多项时会同时返回新的 page_token # 下次遍历可采用该 page_token 获取查询结果 # 示例值:"recn0hoyXL" "page_size": count # 分页大小。示例值:10。数据校验规则:最大值 100 } try: urllib3.disable_warnings() r = requests.get(url=url, headers=headers, params=params, proxies=proxies, verify=False) cls.page_token = r.json()["data"]["page_token"] items = r.json()["data"]["items"] for item in items: print(item) Common.logger().info("列出记录,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("列出记录异常:{}", e) # 检索记录 @classmethod def search_records(cls, record_id): """ 该接口用于根据 record_id 的值检索现有记录 该接口支持调用频率上限为 20 QPS https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table-record/get """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" \ + cls.app_token + "/tables/" + cls.table_id + "/records/" + record_id headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } params = { "text_field_as_array": True, # 控制多行文本字段数据的返回格式, true 表示以数组形式返回。示例值:true # "user_id_type": "", # 用户 ID 类型 # 示例值:"open_id" # 可选值有: # open_id:用户的 open id # union_id:用户的 union id # user_id:用户的 user id # 默认值:open_id "display_formula_ref": True, # 控制公式、查找引用是否显示完整的原样返回结果。示例值:true "automatic_fields": True, # 控制是否返回自动计算的字段 # 例如 created_by/created_time/last_modified_by/last_modified_time,true 表示返回。示例值:true } try: urllib3.disable_warnings() r = requests.get(url=url, headers=headers, params=params, proxies=proxies, verify=False) Common.logger().info("检索记录,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("检索记录异常:{}", e) # 新增记录 @classmethod def create_record(cls, fields): """ 该接口用于在数据表中新增一条记录 该接口支持调用频率上限为 10 QPS https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table-record/create """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" \ + cls.app_token + "/tables/" + cls.table_id + "/records" headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } body = fields try: urllib3.disable_warnings() r = requests.post(url=url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("新增记录,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("新增记录异常:{}", e) # 新增多条记录 @classmethod def create_records(cls, records): """ 该接口用于在数据表中新增多条记录 该接口支持调用频率上限为 10 QPS https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table-record/batch_create """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" \ + cls.app_token + "/tables/" + cls.table_id + "/records/batch_create" headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } body = { "records": records } try: urllib3.disable_warnings() r = requests.post(url=url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("新增多条记录,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("新增多条记录异常:{}", e) # 更新记录 @classmethod def update_record(cls, record_id, fields): """ 该接口用于更新数据表中的一条记录 该接口支持调用频率上限为 10 QPS https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table-record/update """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" \ + cls.app_token + "/tables/" + cls.table_id + "/records/" + record_id headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } body = fields try: urllib3.disable_warnings() r = requests.put(url=url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("更新记录,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("更新记录异常:{}", e) # 更新多条记录 @classmethod def update_records(cls, records): """ 该接口用于更新数据表中的多条记录 该接口支持调用频率上限为 10 QPS https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table-record/batch_update """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" \ + cls.app_token + "/tables/" + cls.table_id + "/records/batch_update" headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } body = records try: urllib3.disable_warnings() r = requests.post(url=url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("更新多条记录,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("更新多条记录异常:{}", e) # 删除记录 @classmethod def del_record(cls, record_id): """ 该接口用于删除数据表中的一条记录 该接口支持调用频率上限为 10 QPS https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table-record/delete """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" \ + cls.app_token + "/tables/" + cls.table_id + "/records/" + record_id headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } try: urllib3.disable_warnings() r = requests.delete(url=url, headers=headers, proxies=proxies, verify=False) Common.logger().info("删除记录,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("删除记录异常:{}", e) # 删除多条记录 @classmethod def del_records(cls, record_ids): """ 该接口用于删除数据表中现有的多条记录 该接口支持调用频率上限为 10 QPS https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table-record/batch_delete """ url = "https://open.feishu.cn/open-apis/bitable/v1/apps/" \ + cls.app_token + "/tables/" + cls.table_id + "/records/batch_delete" headers = { "Authorization": "Bearer " + cls.tenant_access_token(), "Content-Type": "application/json; charset=utf-8" } body = { "records": record_ids # 删除的多条记录id列表。示例值:["recIcJBbvC","recvmiCORa"] } try: urllib3.disable_warnings() r = requests.post(url=url, headers=headers, json=body, proxies=proxies, verify=False) Common.logger().info("删除多条记录,code:{},msg:{}", r.json()["code"], r.json()["msg"]) except Exception as e: Common.logger().error("删除多条记录异常:{}", e) if __name__ == "__main__": # feishu = Feishu() # print(feishu.get_bitable_token()) 'reck6nLiZV' 'recHcfJZnG' 'recxdSMhzE' # 实例化多维表格 bitable = Bitable() # # 获取多维表格元数据 # bitable.get_apps() # # # 列出数据表 # bitable.get_tables() # # # 列出记录 # bitable.list_records(3) # # # 检索记录 # bitable.search_records("recHcfJZnG") # # 新增一条记录 # create_value = { # "fields": { # "uid": "0000000000", # "key_words": "0000000000", # "name": "功能开发🥕", # "screen_name": "功能开发🥕", # "person_url": { # "link": "https://bytedance.feishu.cn/drive/home/", "text": "https://bytedance.feishu.cn/drive/home/" # }, # "description": "功能开发🥕", # "location": "null", # "friends_count": 9999999999, # "followers_count": 9999999999, # "favourites_count": 9999999999, # "listed_count": 9999999999, # "statuses_count": 9999999999, # "media_count": 9999999999, # "display_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "created_at": 1656053209000, # "profile_image_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "profile_banner_url": { # "link": "null", # "text": "null" # }, # "ext_has_nft_avatar": "False", # "verified": "False", # "记录创建时间": 1656053209000, # # "记录修改时间": "" # } # } # bitable.create_record(create_value) # 新增多条记录 # create_values = { # "fields": { # "uid": "0000000000", # "key_words": "0000000000", # "name": "功能开发🥕", # "screen_name": "功能开发🥕", # "person_url": { # "link": "https://bytedance.feishu.cn/drive/home/", "text": "https://bytedance.feishu.cn/drive/home/" # }, # "description": "功能开发🥕", # "location": "null", # "friends_count": 9999999999, # "followers_count": 9999999999, # "favourites_count": 9999999999, # "listed_count": 9999999999, # "statuses_count": 9999999999, # "media_count": 9999999999, # "display_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "created_at": 1656053209000, # "profile_image_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "profile_banner_url": { # "link": "null", # "text": "null" # }, # "ext_has_nft_avatar": "False", # "verified": "False", # "记录创建时间": 1656053209000, # # "记录修改时间": "" # } # } # values_list = [create_values, create_values] # bitable.create_records(values_list) # # 更新一条记录 # use_record_id = "recxdSMhzE" # use_fields = { # "fields": { # "uid": "1111111111", # "key_words": "1111111111", # "name": "功能开发🥕", # "screen_name": "功能开发🥕", # "person_url": { # "link": "https://bytedance.feishu.cn/drive/home/", "text": "https://bytedance.feishu.cn/drive/home/" # }, # "description": "功能开发🥕", # "location": "null", # "friends_count": 9999999999, # "followers_count": 9999999999, # "favourites_count": 9999999999, # "listed_count": 9999999999, # "statuses_count": 9999999999, # "media_count": 9999999999, # "display_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "created_at": 1656053209000, # "profile_image_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "profile_banner_url": { # "link": "null", # "text": "null" # }, # "ext_has_nft_avatar": "False", # "verified": "False", # "记录创建时间": 1656053209000, # # "记录修改时间": "" # } # } # bitable.update_record(use_record_id, use_fields) # # 更新多条记录 # "recxdSMhzE" # "recHcfJZnG" # use_records = { # "records": [ # { # "record_id": "recxdSMhzE", # "fields": { # "uid": "3333333333", # "key_words": "3333333333", # "name": "功能开发🥕", # "screen_name": "功能开发🥕", # "person_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "description": "功能开发🥕", # "location": "null", # "friends_count": 9999999999, # "followers_count": 9999999999, # "favourites_count": 9999999999, # "listed_count": 9999999999, # "statuses_count": 9999999999, # "media_count": 9999999999, # "display_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "created_at": 1656053209000, # "profile_image_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "profile_banner_url": { # "link": "null", # "text": "null" # }, # "ext_has_nft_avatar": "False", # "verified": "False", # "记录创建时间": 1656053209000, # # "记录修改时间": "" # } # }, # { # "record_id": "recHcfJZnG", # "fields": { # "uid": "3333333333", # "key_words": "3333333333", # "name": "功能开发🥕", # "screen_name": "功能开发🥕", # "person_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "description": "功能开发🥕", # "location": "null", # "friends_count": 9999999999, # "followers_count": 9999999999, # "favourites_count": 9999999999, # "listed_count": 9999999999, # "statuses_count": 9999999999, # "media_count": 9999999999, # "display_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "created_at": 1656053209000, # "profile_image_url": { # "link": "https://bytedance.feishu.cn/drive/home/", # "text": "https://bytedance.feishu.cn/drive/home/" # }, # "profile_banner_url": { # "link": "null", # "text": "null" # }, # "ext_has_nft_avatar": "False", # "verified": "False", # "记录创建时间": 1656053209000, # # "记录修改时间": "" # } # } # ] # } # bitable.update_records(use_records) # # 删除一条记录 # bitable.del_record("reck6nLiZV") # # 删除多条记录 # bitable.del_records(['recHcfJZnG', 'recxdSMhzE'])