
    Ng                        d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZ er
d dlmZmZmZ  G d de          Zd	S )
    )annotations)TYPE_CHECKINGAnyIteratorLiteralOptionalTuple)Document)get_from_env)
BaseLoader)BoardCardTrelloClientc                  `    e Zd ZdZddddddd&dZedddd'd            Zd(dZd)dZd*d%Z	dS )+TrelloLoaderz!Load cards from a `Trello` board.Tall)due_datelabelslistclosed)include_card_nameinclude_commentsinclude_checklistcard_filterextra_metadataclientr   
board_namestrr   boolr   r   r    Literal['closed', 'open', 'all']r   Tuple[str, ...]c               h    || _         || _        || _        || _        || _        || _        || _        dS )a  Initialize Trello loader.

        Args:
            client: Trello API client.
            board_name: The name of the Trello board.
            include_card_name: Whether to include the name of the card in the document.
            include_comments: Whether to include the comments on the card in the
                document.
            include_checklist: Whether to include the checklist on the card in the
                document.
            card_filter: Filter on card status. Valid values are "closed", "open",
                "all".
            extra_metadata: List of additional metadata fields to include as document
                metadata.Valid values are "due_date", "labels", "list", "closed".

        N)r   r   r   r   r   r   r   )selfr   r   r   r   r   r   r   s           g/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/trello.py__init__zTrelloLoader.__init__   s@    6 $!2 0!2,&    Napi_keytokenr(   Optional[str]r)   kwargsr   returnc                   	 ddl m} n"# t          $ r}t          d          |d}~ww xY w|pt          dd          }|pt          dd          } |||	          } | ||fi |S )
a  Convenience constructor that builds TrelloClient init param for you.

        Args:
            board_name: The name of the Trello board.
            api_key: Trello API key. Can also be specified as environment variable
                TRELLO_API_KEY.
            token: Trello token. Can also be specified as environment variable
                TRELLO_TOKEN.
            include_card_name: Whether to include the name of the card in the document.
            include_comments: Whether to include the comments on the card in the
                document.
            include_checklist: Whether to include the checklist on the card in the
                document.
            card_filter: Filter on card status. Valid values are "closed", "open",
                "all".
            extra_metadata: List of additional metadata fields to include as document
                metadata.Valid values are "due_date", "labels", "list", "closed".
        r   )r   zWCould not import trello python package. Please install it with `pip install py-trello`.Nr(   TRELLO_API_KEYr)   TRELLO_TOKENr'   )trellor   ImportErrorr   )clsr   r(   r)   r+   r   exr   s           r$   from_credentialszTrelloLoader.from_credentials4   s    8	+++++++ 	 	 	B  	
 F\)5EFF>g~>>gU;;;s6:00000s   	 
(#(Iterator[Document]c              #  2  K   	 ddl m} n"# t          $ r}t          d          |d}~ww xY w|                                 }d |                                D             }|                    | j                  }|D ]}|                     ||          V  dS )zLoads all cards from the specified Trello board.

        You can filter the cards, metadata and text included by using the optional
            parameters.

         Returns:
            A list of documents, one for each card in the board.
        r   BeautifulSoupzK`beautifulsoup4` package not found, please run `pip install beautifulsoup4`Nc                (    i | ]}|j         |j        S  )idname).0	list_items     r$   
<dictcomp>z*TrelloLoader.lazy_load.<locals>.<dictcomp>o   s    VVViY\9>VVVr&   )r   )bs4r8   r1   
_get_board
list_lists	get_cardsr   _card_to_doc)r#   r8   r3   board	list_dictcardscards          r$   	lazy_loadzTrelloLoader.lazy_load\   s      	))))))) 	 	 	0  	 !!VV5CSCSCUCUVVV	D,<== 	5 	5D##D)444444	5 	5s    
*%*r   c                     t           fd j                                        D             d           }|st          d j         d          |S )Nc              3  <   K   | ]}|j         j        k    |V  d S )N)r<   r   )r=   br#   s     r$   	<genexpr>z*TrelloLoader._get_board.<locals>.<genexpr>x   s1      OO1QVt5N5NQ5N5N5N5NOOr&   zBoard `z` not found.)nextr   list_boards
ValueErrorr   )r#   rE   s   ` r$   rA   zTrelloLoader._get_boardu   sf    OOOO//11OOOQU
 
  	FDtDDDEEEr&   rH   r   rF   dictr
   c                   ddl m d}| j        r
|j        dz   }|j                                        r&| |j        d                                          z  }| j        rF|j        D ]>}|j	        r5d |j	        D             }|d|j         dd
                    |          z   z  }?| j        r.fd|j        D             }|dd
                    |          z   z  }|j        |j        |j        d	}d
| j        v rd |j        D             |d
<   d| j        v r|j        |v r||j                 |d<   d| j        v r
|j        |d<   d| j        v r
|j        |d<   t)          ||          S )Nr   r7    
lxmlc                4    g | ]}|d           d|d          S )r<   :stater:   )r=   items     r$   
<listcomp>z-TrelloLoader._card_to_doc.<locals>.<listcomp>   s;       >B4<99$w-99  r&   c                d    g | ],} |d          d         d                                           -S )datatextrU   )get_text)r=   commentr8   s     r$   rZ   z-TrelloLoader._card_to_doc.<locals>.<listcomp>   sJ        gfof5v>>GGII  r&   z	Comments:)titler;   urlr   c                    g | ]	}|j         
S r:   )r<   )r=   labels     r$   rZ   z-TrelloLoader._card_to_doc.<locals>.<listcomp>   s    !F!F!F%*!F!F!Fr&   r   r   r   )page_contentmetadata)r@   r8   r   r<   descriptionstripr^   r   
checklistsitemsjoinr   commentsr;   ra   r   r   list_idr   r   r
   )	r#   rH   rF   text_content	checklistri   rk   re   r8   s	           @r$   rD   zTrelloLoader._card_to_doc~   s   %%%%%%! 	,9t+L!!## 	OMM$*:FCCLLNNNL! 	O!_ O O	? O FOo  E !$;$;$;$;dii>N>N$NNL  	>   #}  H K$))H*=*===L Y'8
 
 t***!F!F$+!F!F!FHXT(((|y((#,T\#: t***!%HX,,,#'=HZ \HEEEEr&   )r   r   r   r   r   r   r   r   r   r   r   r    r   r!   )
r   r   r(   r*   r)   r*   r+   r   r,   r   )r,   r5   )r,   r   )rH   r   rF   rQ   r,   r
   )
__name__
__module____qualname____doc__r%   classmethodr4   rI   rA   rD   r:   r&   r$   r   r      s        ++ #'!%"&8=*R!' !' !' !' !' !'F 
 "&#%1 %1 %1 %1 %1 [%1N5 5 5 52   +F +F +F +F +F +Fr&   r   N)
__future__r   typingr   r   r   r   r   r	   langchain_core.documentsr
   langchain_core.utilsr   )langchain_community.document_loaders.baser   r0   r   r   r   r   r:   r&   r$   <module>ry      s    " " " " " " I I I I I I I I I I I I I I I I - - - - - - - - - - - - @ @ @ @ @ @ 10000000000[F [F [F [F [F: [F [F [F [F [Fr&   