a
    bg                     @  s|   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rhd dlmZmZmZ G dd deZd	S )
    )annotations)TYPE_CHECKINGAnyIteratorLiteralOptionalTuple)Document)get_from_env)
BaseLoader)BoardCardTrelloClientc                	   @  s   e Zd ZdZdddddddddddd	d
dddZedddddddd dddZddddZddddZdddd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_metadatar   strboolz Literal['closed', 'open', 'all']zTuple[str, ...])client
board_namer   r   r   r   r   c                C  s.   || _ || _|| _|| _|| _|| _|| _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    r   y/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/trello.py__init__   s    zTrelloLoader.__init__Napi_keytokenzOptional[str]r   )r   r#   r$   kwargsreturnc             
   K  sz   zddl m} W n. ty> } ztd|W Y d}~n
d}~0 0 |pLtdd}|pZtd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#   ZTRELLO_API_KEYr$   ZTRELLO_TOKENr"   )trellor   ImportErrorr
   )clsr   r#   r$   r%   r   exr   r   r   r    from_credentials4   s    zTrelloLoader.from_credentialszIterator[Document])r&   c              
   c  s   zddl m} W n. ty> } ztd|W Y d}~n
d}~0 0 |  }dd | D }|j| jd}|D ]}| ||V  qld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                 S  s   i | ]}|j |jqS r   )idname).0Z	list_itemr   r   r    
<dictcomp>o       z*TrelloLoader.lazy_load.<locals>.<dictcomp>)r   )bs4r-   r(   
_get_boardZ
list_listsZ	get_cardsr   _card_to_doc)r   r-   r*   board	list_dictZcardscardr   r   r    	lazy_load\   s    	zTrelloLoader.lazy_loadr   c                   s8   t  fdd j D d }|s4td j d|S )Nc                 3  s   | ]}|j  jkr|V  qd S )N)r/   r   )r0   br   r   r    	<genexpr>x   r2   z*TrelloLoader._get_board.<locals>.<genexpr>zBoard `z` not found.)nextr   Zlist_boards
ValueErrorr   )r   r6   r   r;   r    r4   u   s    zTrelloLoader._get_boardr   dictr	   )r8   r7   r&   c                   s<  ddl m  d}| jr |jd }|j r>| |jd 7 }| jr|jD ]6}|j	rJdd |j	D }|d|j dd
| 7 }qJ| jr fdd|jD }|d	d
| 7 }|j|j|jd
}d| jv rdd |jD |d< d| jv r|j|v r||j |d< d| jv r|j|d< d| jv r0|j|d< t||dS )Nr   r,    
lxmlc                 S  s"   g | ]}|d   d|d  qS )r/   :stater   )r0   itemr   r   r    
<listcomp>   s   z-TrelloLoader._card_to_doc.<locals>.<listcomp>c                   s"   g | ]} |d  d d  qS )datatextrB   )get_text)r0   commentr,   r   r    rF      s   z	Comments:)titler.   urlr   c                 S  s   g | ]
}|j qS r   )r/   )r0   labelr   r   r    rF      r2   r   r   r   )Zpage_contentmetadata)r3   r-   r   r/   descriptionstriprI   r   Z
checklistsitemsjoinr   commentsr.   rL   r   r   Zlist_idr   r   r	   )r   r8   r7   Ztext_contentZ	checklistrQ   rS   rN   r   r,   r    r5   ~   s@    






zTrelloLoader._card_to_doc)
__name__
__module____qualname____doc__r!   classmethodr+   r9   r4   r5   r   r   r   r    r      s   #'	r   N)
__future__r   typingr   r   r   r   r   r   Zlangchain_core.documentsr	   Zlangchain_core.utilsr
   Z)langchain_community.document_loaders.baser   r'   r   r   r   r   r   r   r   r    <module>   s    