
    dh                         S SK r S SKJrJrJrJrJr  S SKJr  S SK	J
r
  S SKJr  \ R                  " \5      r " S S\
5      rg)    N)AnyIteratorListOptionalSequence)Document)
BaseLoader)NewsURLLoaderc                       \ rS rSrSr    SS\\\      S\\   S\S\S\	S	S4S
 jjr
S	\\   4S jr\S	\\   4S j5       rS	\\   4S jrSrg)RSSFeedLoader   a  Load news articles from `RSS` feeds using `Unstructured`.

Args:
    urls: URLs for RSS feeds to load. Each articles in the feed is loaded into its own document.
    opml: OPML file to load feed urls from. Only one of urls or opml should be provided.  The value
    can be a URL string, or OPML markup contents as byte or string.
    continue_on_failure: If True, continue loading documents even if
        loading fails for a particular URL.
    show_progress_bar: If True, use tqdm to show a loading progress bar. Requires
        tqdm to be installed, ``pip install tqdm``.
    **newsloader_kwargs: Any additional named arguments to pass to
        NewsURLLoader.

Example:
    .. code-block:: python

        from langchain_community.document_loaders import RSSFeedLoader

        loader = RSSFeedLoader(
            urls=["<url-1>", "<url-2>"],
        )
        docs = loader.load()

The loader uses feedparser to parse RSS feeds.  The feedparser library is not installed by default so you should
install it if using this loader:
https://pythonhosted.org/feedparser/

If you use OPML, you should also install listparser:
https://pythonhosted.org/listparser/

Finally, newspaper is used to process each article:
https://newspaper.readthedocs.io/en/latest/
Nurlsopmlcontinue_on_failureshow_progress_barnewsloader_kwargsreturnc                 j    USL USL :X  a  [        S5      eXl        X l        X0l        X@l        XPl        g)zInitialize with urls or OPML.Nz;Provide either the urls or the opml argument, but not both.)
ValueErrorr   r   r   r   r   )selfr   r   r   r   r   s         `/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/document_loaders/rss.py__init__RSSFeedLoader.__init__/   sG     DLDL
 M  		#6 !2!2    c                     U R                  5       nU R                  (       a   SSKJn  U" U5      n[	        U5      $ ! [         a  n[        S5      UeS nAff = f)Nr   )tqdmzPackage tqdm must be installed if show_progress_bar=True. Please install with 'pip install tqdm' or set show_progress_bar=False.)	lazy_loadr   r   ImportErrorlist)r   iterr   es       r   loadRSSFeedLoader.loadD   s]    ~~!!% :DDz  !/ 	s   < 
AAAc                    U R                   (       a  U R                   $  SS KnUR                  U R                  5      nUR
                   Vs/ sH  oDR                  PM     sn$ ! [         a  n[        S5      UeS nAff = fs  snf )Nr   zPackage listparser must be installed if the opml arg is used. Please install with 'pip install listparser' or use the urls arg instead.)r   
listparserr   parser   feedsurl)r   r%   r!   rssfeeds        r   	_get_urlsRSSFeedLoader._get_urlsR   sy    9999	 tyy)%(YY/YTY//  	$ 		 0s   A# B#
A>-A99A>c              #     #     SS K nU R                   H  n UR                  U5      n[	        USS5      (       a  [        SU SUR                   35      e  UR                   HJ  n[        S
SUR                  /0U R                  D6nUR                  5       S   nX'R                   S'   Uv   ML     M     g ! [         a    [        S5      ef = f! [         a9  nU R                  (       a!  [        R                  SU SU 35         S nAM  UeS nAff = f! [         aD  nU R                  (       a,  [        R                  S	WR                   SU 35         S nAGMI  UeS nAff = f7f)Nr   zMfeedparser package not found, please install it with `pip install feedparser`bozoFzError fetching z, exception: r   r*   zError processing entry  )
feedparserr   r+   r&   getattrr   bozo_exception	Exceptionr   loggererrorentriesr
   linkr   r"   metadata)r   r0   r(   r*   r!   entryloaderarticles           r   r   RSSFeedLoader.lazy_loada   sg    	 >>C!'',4//$)#mD<O<O;PQ  0!\\E* #jj\00F %kkmA.G/2$$V,!M * "  	+ 	  ++LL?3%}QC!HIG  ++LL#:5::,mTUSV!WXGs{   E'B7 E'>CE'AD2E'7CE'
D,DE'DDE'
E$ 6EE'EE$$E')r   r   r   r   r   )NNTF)__name__
__module____qualname____firstlineno____doc__r   r   strboolr   r   r   r   r"   propertyr+   r   r   __static_attributes__r/   r   r   r   r      s     H )-"$("'3x}%3 sm3 "	3
  3 !3 
3*d8n  08C= 0 0$8H- $r   r   )loggingtypingr   r   r   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser	   )langchain_community.document_loaders.newsr
   	getLoggerr=   r4   r   r/   r   r   <module>rL      s5     : : - @ C			8	$yJ yr   