
    7|h                        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y	)
    )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	y)TrelloLoaderz!Load cards from a `Trello` board.Tall)due_datelabelslistclosed)include_card_nameinclude_commentsinclude_checklistcard_filterextra_metadatac               f    || _         || _        || _        || _        || _        || _        || _        y)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)client
board_namer   r   r   r   r   )selfr   r   r   r   r   r   r   s           j/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/document_loaders/trello.py__init__zTrelloLoader.__init__   s:    6 $!2 0!2,&    Napi_keytokenc                   	 ddl m} |xs t        dd      }|xs t        dd      } |||	      } | ||fi |S # t        $ r}t        d      |d}~ww xY w)
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%   kwargsr   exr   s           r    from_credentialszTrelloLoader.from_credentials4   sw    8	+ F\)5EF>g~>gU;6:000  	B 	s   < 	AAAc              #  P  K   	 ddl m} | j                         }|j	                         D ci c]  }|j
                  |j                   }}|j                  | j                        }|D ]  }| j                  ||        y# t        $ r}t        d      |d}~ww xY wc c}w w)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`N)r   )
bs4r1   r*   
_get_board
list_listsidname	get_cardsr   _card_to_doc)r   r1   r-   board	list_item	list_dictcardscards           r    	lazy_loadzTrelloLoader.lazy_load\   s     	) !CHCSCSCUViY\\9>>1V	VD,<,<= 	5D##D)44	5  	0 	 Ws2   B&B "B&B!
:B&	BBBB&c                     t         fd j                  j                         D        d       }|st        d j                   d      |S )Nc              3  V   K   | ]   }|j                   j                  k(  s| " y w)N)r6   r   ).0br   s     r    	<genexpr>z*TrelloLoader._get_board.<locals>.<genexpr>x   s      O1QVVt5NQOs   ))zBoard `z` not found.)nextr   list_boards
ValueErrorr   )r   r9   s   ` r    r3   zTrelloLoader._get_boardu   sH    O//1OQU
 wt&7|DEEr"   c                   ddl m} d}| j                  r|j                  dz   }|j                  j                         r$| ||j                  d      j                         z  }| j                  rg|j                  D ]X  }|j                  s|j                  D cg c]  }|d    d|d     }}|d|j                   ddj                  |      z   z  }Z | j                  rK|j                  D cg c]  } ||d	   d
   d      j                         ! }	}|ddj                  |	      z   z  }|j                  |j                  |j                  d}
d| j                  v r'|j                   D cg c]  }|j                   c}|
d<   d| j                  v r |j"                  |v r||j"                     |
d<   d| j                  v r|j$                  |
d<   d| j                  v r|j&                  |
d<   t)        ||
      S c c}w c c}w c c}w )Nr   r0    
lxmlr6   :statedatatextz	Comments:)titler5   urlr   r   r   r   )page_contentmetadata)r2   r1   r   r6   descriptionstripget_textr   
checklistsitemsjoinr   commentsr5   rP   r   r   list_idr   r   r
   )r   r=   r;   r1   text_content	checklistitemrW   commentrY   rR   labels               r    r8   zTrelloLoader._card_to_doc~   s   %!!99t+L!!#M$*:*:FCLLNNL!!!__ O	??FOoo>B4<.$w-9E  !b(8$;dii>N$NNLO     $}} gfof5v>GGIH  K$))H*===L YY''88
 t***:>++!F%**!FHXT(((||y(#,T\\#: t***!%HX,,,#'==HZ \HEE? "Gs   G:/$G?,H)r   r   r   strr   boolr   ra   r   ra   r   z Literal['closed', 'open', 'all']r   zTuple[str, ...])
r   r`   r$   Optional[str]r%   rb   r,   r   returnr   )rc   zIterator[Document])rc   r   )r=   r   r;   dictrc   r
   )
__name__
__module____qualname____doc__r!   classmethodr.   r>   r3   r8    r"   r    r   r      s    + #'!%"&8=*R!'!' !'
  !' !'  !' 6!' (!'F 
 "&#%1%1 	%1
 %1 %1 
%1 %1N52+Fr"   r   N)
__future__r   typingr   r   r   r   r   r	   langchain_core.documentsr
   langchain_core.utilsr   )langchain_community.document_loaders.baser   r)   r   r   r   r   rj   r"   r    <module>rp      s0    " I I - - @00[F: [Fr"   