From 309aff9caeeb2edc6c1436c15e20bf807fbfacba Mon Sep 17 00:00:00 2001 From: srexrg Date: Tue, 31 Dec 2024 00:41:08 +0530 Subject: [PATCH 1/6] Added Reddit Tool --- cookbook/tools/reddit_tools.py | 15 +++ phi/tools/reddit.py | 178 +++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 cookbook/tools/reddit_tools.py create mode 100644 phi/tools/reddit.py diff --git a/cookbook/tools/reddit_tools.py b/cookbook/tools/reddit_tools.py new file mode 100644 index 0000000000..476c1f6061 --- /dev/null +++ b/cookbook/tools/reddit_tools.py @@ -0,0 +1,15 @@ +from phi.agent import Agent +from phi.tools.reddit import RedditTools + +agent = Agent( + instructions=[ + "Use your tools to answer questions about Reddit content and statistics", + "Do not interact with posts or comments (no voting, commenting, or posting)", + "Respect Reddit's content policies and NSFW restrictions", + "When analyzing subreddits, provide relevant statistics and trends", + ], + tools=[RedditTools()], + show_tool_calls=True, +) + +agent.print_response("What are the top 5 posts on r/SAAS this week ?", stream=True) diff --git a/phi/tools/reddit.py b/phi/tools/reddit.py new file mode 100644 index 0000000000..ebf68ebd3a --- /dev/null +++ b/phi/tools/reddit.py @@ -0,0 +1,178 @@ +import json +from os import getenv +from typing import Optional, Dict, List, Union +from phi.tools import Toolkit +from phi.utils.log import logger + +try: + import praw # type: ignore +except ImportError: + raise ImportError("`praw` not installed.") + + +class RedditTools(Toolkit): + reddit: Optional[praw.Reddit] + + def __init__( + self, + client_id: Optional[str] = None, + client_secret: Optional[str] = None, + user_agent: Optional[str] = None, + get_user_info: bool = True, + get_top_posts: bool = True, + get_subreddit_info: bool = True, + get_trending_subreddits: bool = True, + get_subreddit_stats: bool = True, + ): + super().__init__(name="reddit") + + self.client_id = client_id or getenv("REDDIT_CLIENT_ID") + self.client_secret = client_secret or getenv("REDDIT_CLIENT_SECRET") + self.user_agent = user_agent or getenv("REDDIT_USER_AGENT", "RedditTools v1.0") + + self.reddit = None + if all([self.client_id, self.client_secret]): + self.reddit = praw.Reddit( + client_id=self.client_id, client_secret=self.client_secret, user_agent=self.user_agent + ) + else: + logger.warning("Missing Reddit API credentials") + + if get_user_info: + self.register(self.get_user_info) + if get_top_posts: + self.register(self.get_top_posts) + if get_subreddit_info: + self.register(self.get_subreddit_info) + if get_trending_subreddits: + self.register(self.get_trending_subreddits) + if get_subreddit_stats: + self.register(self.get_subreddit_stats) + + def get_user_info(self, username: str) -> str: + """Get information about a Reddit user.""" + if not self.reddit: + return "Please provide Reddit API credentials" + + try: + logger.info(f"Getting info for u/{username}") + + user = self.reddit.redditor(username) + info: Dict[str, Union[str, int, bool, float]] = { + "name": user.name, + "comment_karma": user.comment_karma, + "link_karma": user.link_karma, + "is_mod": user.is_mod, + "is_gold": user.is_gold, + "is_employee": user.is_employee, + "created_utc": user.created_utc, + } + + return json.dumps(info) + + except Exception as e: + return f"Error getting user info: {e}" + + def get_top_posts(self, subreddit: str, time_filter: str = "week", limit: int = 10) -> str: + """ + Get top posts from a subreddit for a specific time period. + + Args: + subreddit (str): Name of the subreddit. + time_filter (str): Time period to filter posts. + limit (int): Number of posts to fetch. + + Returns: + str: JSON string containing top posts. + """ + if not self.reddit: + return "Please provide Reddit API credentials" + + try: + posts = self.reddit.subreddit(subreddit).top(time_filter=time_filter, limit=limit) + top_posts: List[Dict[str, Union[str, int, float]]] = [ + { + "title": post.title, + "score": post.score, + "url": post.url, + "author": str(post.author), + "created_utc": post.created_utc, + } + for post in posts + ] + return json.dumps({"top_posts": top_posts}) + except Exception as e: + return f"Error getting top posts: {e}" + + def get_subreddit_info(self, subreddit_name: str) -> str: + """ + Get information about a specific subreddit. + + Args: + subreddit_name (str): Name of the subreddit. + + Returns: + str: JSON string containing subreddit information. + """ + if not self.reddit: + return "Please provide Reddit API credentials" + + try: + logger.info(f"Getting info for r/{subreddit_name}") + + subreddit = self.reddit.subreddit(subreddit_name) + info: Dict[str, Union[str, int, bool, float]] = { + "display_name": subreddit.display_name, + "title": subreddit.title, + "description": subreddit.description, + "subscribers": subreddit.subscribers, + "created_utc": subreddit.created_utc, + "over18": subreddit.over18, + "public_description": subreddit.public_description, + "url": subreddit.url, + } + + return json.dumps(info) + + except Exception as e: + return f"Error getting subreddit info: {e}" + + def get_trending_subreddits(self) -> str: + """Get currently trending subreddits.""" + if not self.reddit: + return "Please provide Reddit API credentials" + + try: + popular_subreddits = self.reddit.subreddits.popular(limit=5) + trending: List[str] = [subreddit.display_name for subreddit in popular_subreddits] + return json.dumps({"trending_subreddits": trending}) + except Exception as e: + return f"Error getting trending subreddits: {e}" + + def get_subreddit_stats(self, subreddit: str) -> str: + """ + Get statistics about a subreddit. + + Args: + subreddit (str): Name of the subreddit. + + Returns: + str: JSON string containing subreddit statistics + """ + if not self.reddit: + return "Please provide Reddit API credentials" + + try: + sub = self.reddit.subreddit(subreddit) + stats: Dict[str, Union[str, int, bool, float]] = { + "display_name": sub.display_name, + "subscribers": sub.subscribers, + "active_users": sub.active_user_count, + "description": sub.description, + "created_utc": sub.created_utc, + "over18": sub.over18, + "public_description": sub.public_description, + } + return json.dumps({"subreddit_stats": stats}) + except Exception as e: + return f"Error getting subreddit stats: {e}" From 200fba39af01215c4225c6c85eabefe4b3e20ab7 Mon Sep 17 00:00:00 2001 From: srexrg Date: Tue, 31 Dec 2024 17:59:42 +0530 Subject: [PATCH 2/6] Updated with post creation method and cookbook examples --- .../agents/10_reddit_post_generator.py | 53 +++++++++++++++++ cookbook/tools/reddit_tools.py | 1 - phi/tools/reddit.py | 58 +++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 cookbook/examples/agents/10_reddit_post_generator.py diff --git a/cookbook/examples/agents/10_reddit_post_generator.py b/cookbook/examples/agents/10_reddit_post_generator.py new file mode 100644 index 0000000000..a2da31ab52 --- /dev/null +++ b/cookbook/examples/agents/10_reddit_post_generator.py @@ -0,0 +1,53 @@ +from phi.agent import Agent +from phi.tools.duckduckgo import DuckDuckGo +from phi.tools.reddit import RedditTools + + +web_searcher = Agent( + name="Web Searcher", + role="Searches the web for information on a topic", + description="An intelligent agent that performs comprehensive web searches to gather current and accurate information", + tools=[DuckDuckGo()], + instructions=[ + "1. Perform focused web searches using relevant keywords", + "2. Filter results for credibility and recency", + "3. Extract key information and main points", + "4. Organize information in a logical structure", + "5. Verify facts from multiple sources when possible", + "6. Focus on authoritative and reliable sources", + ], +) + +reddit_agent = Agent( + name="Reddit Agent", + role="Uploads post on Reddit", + description="Specialized agent for crafting and publishing engaging Reddit posts", + tools=[RedditTools()], + instructions=[ + "1. Get information regarding the subreddit", + "2. Create attention-grabbing yet accurate titles", + "3. Format posts using proper Reddit markdown", + "4. Avoid including links ", + "5. Follow subreddit-specific rules and guidelines", + "6. Structure content for maximum readability", + "7. Add appropriate tags and flairs if required", + ], + show_tool_calls=True, +) + +post_team = Agent( + team=[web_searcher, reddit_agent], + instructions=[ + "Work together to create engaging and informative Reddit posts", + "Start by researching the topic thoroughly using web searches", + "Craft a well-structured post with accurate information and sources", + "Follow Reddit guidelines and best practices for posting", + ], + show_tool_calls=True, + markdown=True, +) + +post_team.print_response( + "Create a post on web technologies and frameworks to focus in 2025 on the subreddit r/webdev ", + stream=True, +) diff --git a/cookbook/tools/reddit_tools.py b/cookbook/tools/reddit_tools.py index 476c1f6061..cbbcd4e3d4 100644 --- a/cookbook/tools/reddit_tools.py +++ b/cookbook/tools/reddit_tools.py @@ -4,7 +4,6 @@ agent = Agent( instructions=[ "Use your tools to answer questions about Reddit content and statistics", - "Do not interact with posts or comments (no voting, commenting, or posting)", "Respect Reddit's content policies and NSFW restrictions", "When analyzing subreddits, provide relevant statistics and trends", ], diff --git a/phi/tools/reddit.py b/phi/tools/reddit.py index ebf68ebd3a..ef232c8a2e 100644 --- a/phi/tools/reddit.py +++ b/phi/tools/reddit.py @@ -176,3 +176,61 @@ def get_subreddit_stats(self, subreddit: str) -> str: return json.dumps({"subreddit_stats": stats}) except Exception as e: return f"Error getting subreddit stats: {e}" + + def create_post(self, subreddit: str, title: str, content: str, flair: Optional[str] = None, is_self: bool = True) -> str: + """ + Create a new post in a subreddit. + + Args: + subreddit (str): Name of the subreddit to post in. + title (str): Title of the post. + content (str): Content of the post (text for self posts, URL for link posts). + flair (Optional[str]): Flair to add to the post. Must be an available flair in the subreddit. + is_self (bool): Whether this is a self (text) post (True) or link post (False). + Returns: + str: JSON string containing the created post information. + """ + if not self.reddit: + return "Please provide Reddit API credentials" + + if not self._check_user_auth(): + return "User authentication required for posting. Please provide username and password." + + try: + logger.info(f"Creating post in r/{subreddit}") + + subreddit_obj = self.reddit.subreddit(subreddit) + + if flair: + available_flairs = [f['text'] for f in subreddit_obj.flair.link_templates] + if flair not in available_flairs: + return f"Invalid flair. Available flairs: {', '.join(available_flairs)}" + + if is_self: + submission = subreddit_obj.submit( + title=title, + selftext=content, + flair_id=flair, + ) + else: + submission = subreddit_obj.submit( + title=title, + url=content, + flair_id=flair, + ) + logger.info(f"Post created: {submission.permalink}") + + post_info: Dict[str, Union[str, int, float]] = { + "id": submission.id, + "title": submission.title, + "url": submission.url, + "permalink": submission.permalink, + "created_utc": submission.created_utc, + "author": str(submission.author), + "flair": submission.link_flair_text + } + + return json.dumps({"post": post_info}) + + except Exception as e: + return f"Error creating post: {e}" From 4b28eadc7e3001a25a29e62431b771031ddeb679 Mon Sep 17 00:00:00 2001 From: srexrg Date: Tue, 31 Dec 2024 18:05:58 +0530 Subject: [PATCH 3/6] updated auth checks and format errors --- phi/tools/reddit.py | 83 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 17 deletions(-) diff --git a/phi/tools/reddit.py b/phi/tools/reddit.py index ef232c8a2e..db382f8c21 100644 --- a/phi/tools/reddit.py +++ b/phi/tools/reddit.py @@ -18,23 +18,45 @@ def __init__( client_id: Optional[str] = None, client_secret: Optional[str] = None, user_agent: Optional[str] = None, + username: Optional[str] = None, + password: Optional[str] = None, get_user_info: bool = True, get_top_posts: bool = True, get_subreddit_info: bool = True, get_trending_subreddits: bool = True, get_subreddit_stats: bool = True, + create_post: bool = True, ): super().__init__(name="reddit") + # Get credentials from environment variables if not provided self.client_id = client_id or getenv("REDDIT_CLIENT_ID") self.client_secret = client_secret or getenv("REDDIT_CLIENT_SECRET") self.user_agent = user_agent or getenv("REDDIT_USER_AGENT", "RedditTools v1.0") + self.username = username or getenv("REDDIT_USERNAME") + self.password = password or getenv("REDDIT_PASSWORD") self.reddit = None + # Check if we have all required credentials if all([self.client_id, self.client_secret]): - self.reddit = praw.Reddit( - client_id=self.client_id, client_secret=self.client_secret, user_agent=self.user_agent - ) + # Initialize with read-only access if no user credentials + if not all([self.username, self.password]): + logger.info("Initializing Reddit client with read-only access") + self.reddit = praw.Reddit( + client_id=self.client_id, + client_secret=self.client_secret, + user_agent=self.user_agent, + ) + # Initialize with user authentication if credentials provided + else: + logger.info(f"Initializing Reddit client with user authentication for u/{self.username}") + self.reddit = praw.Reddit( + client_id=self.client_id, + client_secret=self.client_secret, + user_agent=self.user_agent, + username=self.username, + password=self.password, + ) else: logger.warning("Missing Reddit API credentials") @@ -48,6 +70,30 @@ def __init__( self.register(self.get_trending_subreddits) if get_subreddit_stats: self.register(self.get_subreddit_stats) + if create_post: + self.register(self.create_post) + + def _check_user_auth(self) -> bool: + """ + Check if user authentication is available for actions that require it. + Returns: + bool: True if user is authenticated, False otherwise + """ + if not self.reddit: + logger.error("Reddit client not initialized") + return False + + if not all([self.username, self.password]): + logger.error("User authentication required. Please provide username and password.") + return False + + try: + # Verify authentication by checking if we can get the authenticated user + self.reddit.user.me() + return True + except Exception as e: + logger.error(f"Authentication error: {e}") + return False def get_user_info(self, username: str) -> str: """Get information about a Reddit user.""" @@ -76,12 +122,10 @@ def get_user_info(self, username: str) -> str: def get_top_posts(self, subreddit: str, time_filter: str = "week", limit: int = 10) -> str: """ Get top posts from a subreddit for a specific time period. - Args: subreddit (str): Name of the subreddit. time_filter (str): Time period to filter posts. limit (int): Number of posts to fetch. - Returns: str: JSON string containing top posts. """ @@ -107,10 +151,8 @@ def get_top_posts(self, subreddit: str, time_filter: str = "week", limit: int = def get_subreddit_info(self, subreddit_name: str) -> str: """ Get information about a specific subreddit. - Args: subreddit_name (str): Name of the subreddit. - Returns: str: JSON string containing subreddit information. """ @@ -121,13 +163,15 @@ def get_subreddit_info(self, subreddit_name: str) -> str: logger.info(f"Getting info for r/{subreddit_name}") subreddit = self.reddit.subreddit(subreddit_name) - info: Dict[str, Union[str, int, bool, float]] = { + flairs = [flair["text"] for flair in subreddit.flair.link_templates] + info: Dict[str, Union[str, int, bool, float, List[str]]] = { "display_name": subreddit.display_name, "title": subreddit.title, "description": subreddit.description, "subscribers": subreddit.subscribers, "created_utc": subreddit.created_utc, "over18": subreddit.over18, + "available_flairs": flairs, "public_description": subreddit.public_description, "url": subreddit.url, } @@ -152,10 +196,8 @@ def get_trending_subreddits(self) -> str: def get_subreddit_stats(self, subreddit: str) -> str: """ Get statistics about a subreddit. - Args: subreddit (str): Name of the subreddit. - Returns: str: JSON string containing subreddit statistics """ @@ -176,11 +218,18 @@ def get_subreddit_stats(self, subreddit: str) -> str: return json.dumps({"subreddit_stats": stats}) except Exception as e: return f"Error getting subreddit stats: {e}" - - def create_post(self, subreddit: str, title: str, content: str, flair: Optional[str] = None, is_self: bool = True) -> str: + + def create_post( + self, + subreddit: str, + title: str, + content: str, + flair: Optional[str] = None, + is_self: bool = True, + ) -> str: """ Create a new post in a subreddit. - + Args: subreddit (str): Name of the subreddit to post in. title (str): Title of the post. @@ -200,9 +249,9 @@ def create_post(self, subreddit: str, title: str, content: str, flair: Optional[ logger.info(f"Creating post in r/{subreddit}") subreddit_obj = self.reddit.subreddit(subreddit) - + if flair: - available_flairs = [f['text'] for f in subreddit_obj.flair.link_templates] + available_flairs = [f["text"] for f in subreddit_obj.flair.link_templates] if flair not in available_flairs: return f"Invalid flair. Available flairs: {', '.join(available_flairs)}" @@ -211,7 +260,7 @@ def create_post(self, subreddit: str, title: str, content: str, flair: Optional[ title=title, selftext=content, flair_id=flair, - ) + ) else: submission = subreddit_obj.submit( title=title, @@ -227,7 +276,7 @@ def create_post(self, subreddit: str, title: str, content: str, flair: Optional[ "permalink": submission.permalink, "created_utc": submission.created_utc, "author": str(submission.author), - "flair": submission.link_flair_text + "flair": submission.link_flair_text, } return json.dumps({"post": post_info}) From bc3d9b802e4c223cff70fc21072405c48bff14e2 Mon Sep 17 00:00:00 2001 From: srexrg Date: Mon, 6 Jan 2025 23:53:43 +0530 Subject: [PATCH 4/6] added steps to get reddit credentials --- phi/tools/reddit.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/phi/tools/reddit.py b/phi/tools/reddit.py index db382f8c21..26aae38e19 100644 --- a/phi/tools/reddit.py +++ b/phi/tools/reddit.py @@ -1,3 +1,29 @@ +""" +Steps to get Reddit credentials: + +1. Create/Login to Reddit account + - Go to https://www.reddit.com + +2. Create a Reddit App + - Go to https://www.reddit.com/prefs/apps + - Click "Create App" or "Create Another App" button + - Fill in required details: + * Name: Your app name + * App type: Select "script" + * Description: Brief description + * About url: Your website (can be http://localhost) + * Redirect uri: http://localhost:8080 + - Click "Create app" button + +3. Get credentials + - client_id: Found under your app name (looks like a random string) + - client_secret: Listed as "secret" + - user_agent: Format as: "platform:app_id:version (by /u/username)" + - username: Your Reddit username + - password: Your Reddit account password + +""" + import json from os import getenv from typing import Optional, Dict, List, Union @@ -7,7 +33,7 @@ try: import praw # type: ignore except ImportError: - raise ImportError("`praw` not installed.") + raise ImportError("praw` not installed. Please install using `pip install praw`") class RedditTools(Toolkit): From 089c3600760b1ef3636f6dc613c3193df4b5c432 Mon Sep 17 00:00:00 2001 From: srexrg Date: Mon, 6 Jan 2025 23:58:52 +0530 Subject: [PATCH 5/6] moved reddit credentials steps to cookbook --- cookbook/tools/reddit_tools.py | 25 +++++++++++++++++++++++++ phi/tools/reddit.py | 26 -------------------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/cookbook/tools/reddit_tools.py b/cookbook/tools/reddit_tools.py index cbbcd4e3d4..2bfca342b5 100644 --- a/cookbook/tools/reddit_tools.py +++ b/cookbook/tools/reddit_tools.py @@ -1,3 +1,28 @@ +""" +Steps to get Reddit credentials: + +1. Create/Login to Reddit account + - Go to https://www.reddit.com + +2. Create a Reddit App + - Go to https://www.reddit.com/prefs/apps + - Click "Create App" or "Create Another App" button + - Fill in required details: + * Name: Your app name + * App type: Select "script" + * Description: Brief description + * About url: Your website (can be http://localhost) + * Redirect uri: http://localhost:8080 + - Click "Create app" button + +3. Get credentials + - client_id: Found under your app name (looks like a random string) + - client_secret: Listed as "secret" + - user_agent: Format as: "platform:app_id:version (by /u/username)" + - username: Your Reddit username + - password: Your Reddit account password + +""" from phi.agent import Agent from phi.tools.reddit import RedditTools diff --git a/phi/tools/reddit.py b/phi/tools/reddit.py index 26aae38e19..6068688f68 100644 --- a/phi/tools/reddit.py +++ b/phi/tools/reddit.py @@ -1,29 +1,3 @@ -""" -Steps to get Reddit credentials: - -1. Create/Login to Reddit account - - Go to https://www.reddit.com - -2. Create a Reddit App - - Go to https://www.reddit.com/prefs/apps - - Click "Create App" or "Create Another App" button - - Fill in required details: - * Name: Your app name - * App type: Select "script" - * Description: Brief description - * About url: Your website (can be http://localhost) - * Redirect uri: http://localhost:8080 - - Click "Create app" button - -3. Get credentials - - client_id: Found under your app name (looks like a random string) - - client_secret: Listed as "secret" - - user_agent: Format as: "platform:app_id:version (by /u/username)" - - username: Your Reddit username - - password: Your Reddit account password - -""" - import json from os import getenv from typing import Optional, Dict, List, Union From 9cbcea2c052456a9fbc190a5092fb1bacda92f9a Mon Sep 17 00:00:00 2001 From: srexrg Date: Tue, 7 Jan 2025 20:31:31 +0530 Subject: [PATCH 6/6] accepting user instance of praw.reddit --- phi/tools/reddit.py | 65 ++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/phi/tools/reddit.py b/phi/tools/reddit.py index 6068688f68..943e99d05a 100644 --- a/phi/tools/reddit.py +++ b/phi/tools/reddit.py @@ -11,10 +11,9 @@ class RedditTools(Toolkit): - reddit: Optional[praw.Reddit] - def __init__( self, + reddit_instance: Optional[praw.Reddit] = None, client_id: Optional[str] = None, client_secret: Optional[str] = None, user_agent: Optional[str] = None, @@ -29,36 +28,40 @@ def __init__( ): super().__init__(name="reddit") - # Get credentials from environment variables if not provided - self.client_id = client_id or getenv("REDDIT_CLIENT_ID") - self.client_secret = client_secret or getenv("REDDIT_CLIENT_SECRET") - self.user_agent = user_agent or getenv("REDDIT_USER_AGENT", "RedditTools v1.0") - self.username = username or getenv("REDDIT_USERNAME") - self.password = password or getenv("REDDIT_PASSWORD") - - self.reddit = None - # Check if we have all required credentials - if all([self.client_id, self.client_secret]): - # Initialize with read-only access if no user credentials - if not all([self.username, self.password]): - logger.info("Initializing Reddit client with read-only access") - self.reddit = praw.Reddit( - client_id=self.client_id, - client_secret=self.client_secret, - user_agent=self.user_agent, - ) - # Initialize with user authentication if credentials provided - else: - logger.info(f"Initializing Reddit client with user authentication for u/{self.username}") - self.reddit = praw.Reddit( - client_id=self.client_id, - client_secret=self.client_secret, - user_agent=self.user_agent, - username=self.username, - password=self.password, - ) + if reddit_instance is not None: + logger.info("Using provided Reddit instance") + self.reddit = reddit_instance else: - logger.warning("Missing Reddit API credentials") + # Get credentials from environment variables if not provided + self.client_id = client_id or getenv("REDDIT_CLIENT_ID") + self.client_secret = client_secret or getenv("REDDIT_CLIENT_SECRET") + self.user_agent = user_agent or getenv("REDDIT_USER_AGENT", "RedditTools v1.0") + self.username = username or getenv("REDDIT_USERNAME") + self.password = password or getenv("REDDIT_PASSWORD") + + self.reddit = None + # Check if we have all required credentials + if all([self.client_id, self.client_secret]): + # Initialize with read-only access if no user credentials + if not all([self.username, self.password]): + logger.info("Initializing Reddit client with read-only access") + self.reddit = praw.Reddit( + client_id=self.client_id, + client_secret=self.client_secret, + user_agent=self.user_agent, + ) + # Initialize with user authentication if credentials provided + else: + logger.info(f"Initializing Reddit client with user authentication for u/{self.username}") + self.reddit = praw.Reddit( + client_id=self.client_id, + client_secret=self.client_secret, + user_agent=self.user_agent, + username=self.username, + password=self.password, + ) + else: + logger.warning("Missing Reddit API credentials") if get_user_info: self.register(self.get_user_info)