[docs]classLarkSuiteDocLoader(BaseLoader):"""Load from `LarkSuite` (`FeiShu`)."""
[docs]def__init__(self,domain:str,access_token:str,document_id:str):"""Initialize with domain, access_token (tenant / user), and document_id. Args: domain: The domain to load the LarkSuite. access_token: The access_token to use. document_id: The document_id to load. """self.domain=domainself.access_token=access_tokenself.document_id=document_id
def_get_larksuite_api_json_data(self,api_url:str)->Any:"""Get LarkSuite (FeiShu) API response json data."""headers={"Authorization":f"Bearer {self.access_token}"}request=urllib.request.Request(api_url,headers=headers)withurllib.request.urlopen(request)asresponse:json_data=json.loads(response.read().decode())returnjson_data
[docs]classLarkSuiteWikiLoader(LarkSuiteDocLoader):"""Load from `LarkSuite` (`FeiShu`) wiki."""
[docs]def__init__(self,domain:str,access_token:str,wiki_id:str):"""Initialize with domain, access_token (tenant / user), and wiki_id. Args: domain: The domain to load the LarkSuite. access_token: The access_token to use. wiki_id: The wiki_id to load. """self.domain=domainself.access_token=access_tokenself.wiki_id=wiki_idself.document_id=""
[docs]deflazy_load(self)->Iterator[Document]:"""Lazy load LarkSuite (FeiShu) wiki document."""# convert Feishu wiki id to document idifnotself.document_id:wiki_url_prefix=f"{self.domain}/open-apis/wiki/v2/spaces/get_node"wiki_node_info_json=self._get_larksuite_api_json_data(f"{wiki_url_prefix}?token={self.wiki_id}")self.document_id=wiki_node_info_json["data"]["node"]["obj_token"]yield fromsuper().lazy_load()