o
    Zh                     @   sX   d dl Z d dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZ G dd deZdS )    N)AnyList)Document)stringify_dict)
BaseLoaderc                   @   sT   e Zd ZdZdededefddZdefdd	Zdefd
dZde	e
 fddZdS )FigmaFileLoaderzLoad `Figma` file.access_tokenidskeyc                 C   s   || _ || _|| _dS )zInitialize with access token, ids, and key.

        Args:
            access_token: The access token for the Figma REST API.
            ids: The ids of the Figma file.
            key: The key for the Figma file
        N)r   r	   r
   )selfr   r	   r
    r   a/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/figma.py__init__   s   
zFigmaFileLoader.__init__returnc                 C   s   d| j | jf }|S )Nz.https://api.figma.com/v1/files/%s/nodes?ids=%s)r
   r	   )r   Zapi_urlr   r   r   _construct_figma_api_url   s
   z(FigmaFileLoader._construct_figma_api_urlc                 C   sd   d| j i}tjj|  |d}tj|}t| 	 }|W  d   S 1 s+w   Y  dS )z#Get Figma file from Figma REST API.zX-Figma-Token)headersN)
r   urllibrequestRequestr   urlopenjsonloadsreaddecode)r   r   r   responseZ	json_datar   r   r   _get_figma_file!   s   
$zFigmaFileLoader._get_figma_filec                 C   s*   |   }t|}d|  i}t||dgS )z	Load filesource)Zpage_contentmetadata)r   r   r   r   )r   datatextr   r   r   r   load+   s   zFigmaFileLoader.loadN)__name__
__module____qualname____doc__strr   r   r   r   r   r   r    r   r   r   r   r      s    
r   )r   urllib.requestr   typingr   r   Zlangchain_core.documentsr   Zlangchain_core.utilsr   Z)langchain_community.document_loaders.baser   r   r   r   r   r   <module>   s    