
    Ng                     f    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e          ZdS )    N)AnyList)Document)stringify_dict)
BaseLoaderc                   V    e Zd ZdZdededefdZdefdZdefdZde	e
         fd	Zd
S )FigmaFileLoaderzLoad `Figma` file.access_tokenidskeyc                 0    || _         || _        || _        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   s       f/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/figma.py__init__zFigmaFileLoader.__init__   s     )    returnc                 *    d| j         d| j        }|S )Nzhttps://api.figma.com/v1/files/z/nodes?ids=)r   r   )r   api_urls     r   _construct_figma_api_urlz(FigmaFileLoader._construct_figma_api_url   s"     HHHHH
 r   c                 `   d| j         i}t          j                            |                                 |          }t          j                            |          5 }t          j        |                                	                                          }|cddd           S # 1 swxY 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   response	json_datas        r   _get_figma_filezFigmaFileLoader._get_figma_file!   s    "D$56.(())++W ) 
 
 ^##G,, 	
8==??#9#9#;#;<<I	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   :B##B'*B'c                     |                                  }t          |          }d|                                 i}t          ||          gS )z	Load filesource)page_contentmetadata)r"   r   r   r   )r   datatextr&   s       r   loadzFigmaFileLoader.load+   sL    ##%%d##d;;==>dX>>>??r   N)__name__
__module____qualname____doc__strr   r   r   r"   r   r   r)    r   r   r	   r	      s        
S 
s 
 
 
 
 
#        @d8n @ @ @ @ @ @r   r	   )r   urllib.requestr   typingr   r   langchain_core.documentsr   langchain_core.utilsr   )langchain_community.document_loaders.baser   r	   r/   r   r   <module>r5      s                 - - - - - - / / / / / / @ @ @ @ @ @%@ %@ %@ %@ %@j %@ %@ %@ %@ %@r   