
    dh                    z    S SK Jr  S SKJrJrJrJrJr  S SKJ	r	  S SK
Jr  \(       a  S SKrS	S jr " S S\5      rg)
    )annotations)TYPE_CHECKINGIterableListOptionalSequence)Document)
BaseLoaderNc                 B     SS K n U $ ! [         a    [        S5      ef = f)Nr   zApraw package not found, please install it with `pip install praw`)prawImportError)r   s    c/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/document_loaders/reddit.py_dependable_praw_importr      s2    

 K	  
O
 	

s    c                      \ rS rSrSrS/S4             SS jjrSS jr        SS jr        SS jrS	r	g
)RedditPostsLoader   zLoad `Reddit` posts.

Read posts on a subreddit.
First, you need to go to
https://www.reddit.com/prefs/apps/
and create your application
new
   c                X    Xl         X l        X0l        X@l        XPl        X`l        Xpl        g)a  
Initialize with client_id, client_secret, user_agent, search_queries, mode,
    categories, number_posts.
Example: https://www.reddit.com/r/learnpython/

Args:
    client_id: Reddit client id.
    client_secret: Reddit client secret.
    user_agent: Reddit user agent.
    search_queries: The search queries.
    mode: The mode.
    categories: The categories. Default: ["new"]
    number_posts: The number of posts. Default: 10
N)	client_idclient_secret
user_agentsearch_queriesmode
categoriesnumber_posts)selfr   r   r   r   r   r   r   s           r   __init__RedditPostsLoader.__init__    s*    0 #*$,	$(    c                   [        5       nUR                  " U R                  U R                  U R                  S9n/ nU R
                  S:X  aI  U R                   H7  nU R                   H$  nU R                  XEUS9nUR                  U5        M&     M9     U$ U R
                  S:X  aI  U R                   H7  nU R                   H$  nU R                  XEUS9nUR                  U5        M&     M9     U$ [        S5      e)zLoad reddits.)r   r   r   	subreddit)search_querycategoryredditusernamez@mode not correct, please enter 'username' or 'subreddit' as mode)r   Redditr   r   r   r   r   r   _subreddit_posts_loaderextend_user_posts_loader
ValueError)r   r   r%   resultsr#   r$   docss          r   loadRedditPostsLoader.load@   s    &(nn,,
 #%99# $ 3 3 $H77%1V 8 D NN4(	 !0 !4(  YY*$ $ 3 3 $H22%1V 3 D NN4(	 !0 !4 	 R r    c           	   #  0  #    UR                  U5      n[        XB5      nU" U R                  S9n U H_  nUR                  UUR                  UR
                  UR                  UR                  UR                  S.n[        UR                  US9v   Ma     g 7fN)limit)post_subredditpost_category
post_title
post_scorepost_idpost_urlpost_author)page_contentmetadata)r"   getattrr   subreddit_name_prefixedtitlescoreidurlauthorr	   selftext)	r   r#   r$   r%   r"   method	cat_postspostr;   s	            r   r(   )RedditPostsLoader._subreddit_posts_loaderc   s      $$\2	-!2!23	0D"&">">!)"jj"jj77 HH#{{H !]]!  s   BBc           	   #  F  #    UR                  U5      n[        UR                  U5      nU" U R                  S9n U H_  nUR                  UUR
                  UR                  UR                  UR                  UR                  S.n[        UR                  US9v   Ma     g 7fr1   )redditorr<   submissionsr   r=   r>   r?   r@   rA   rB   r	   rC   )	r   r#   r$   r%   userrD   rE   rF   r;   s	            r   r*   $RedditPostsLoader._user_posts_loaderz   s      |,))84!2!23	0D"&">">!)"jj"jj77 HH#{{H !]]!  s   BB!)r   r   r   r   r   r   r   N)r   strr   rM   r   rM   r   Sequence[str]r   rM   r   rN   r   zOptional[int])returnzList[Document])r#   rM   r$   rM   r%   zpraw.reddit.RedditrO   zIterable[Document])
__name__
__module____qualname____firstlineno____doc__r   r.   r(   r*   __static_attributes__ r    r   r   r      s     &+G&()) ) 	)
 &) ) ") $)@!F+.8J	.+.8J	r    r   )rO   r   )
__future__r   typingr   r   r   r   r   langchain_core.documentsr	   )langchain_community.document_loaders.baser
   r   r   r   rV   r    r   <module>r[      s-    " D D - @x
 xr    