From 09d12ae173de885b5b66d6ae4f8116a5ed8a799c Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Sat, 17 Jan 2026 16:12:18 +0000 Subject: [PATCH] Add logging to reddit api class --- connectors/reddit_api.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/connectors/reddit_api.py b/connectors/reddit_api.py index 16041ff..56af2d0 100644 --- a/connectors/reddit_api.py +++ b/connectors/reddit_api.py @@ -1,6 +1,10 @@ +import requests +import logging + from dto.post import Post from dto.user import User -import requests + +logger = logging.getLogger(__name__) class RedditAPI: def __init__(self): @@ -13,6 +17,8 @@ class RedditAPI: 'limit': limit, 't': timeframe } + + logger.info(f"Fetching top posts from subreddit: {subreddit} with limit {limit} and timeframe '{timeframe}'") url = f"r/{subreddit}/top.json" data = self._fetch_data(url, params) return self._parse_posts(data) @@ -25,16 +31,19 @@ class RedditAPI: 'sort': 'top', "t": timeframe } + + logger.info(f"Searching subreddit '{subreddit}' for '{search}' with limit {limit} and timeframe '{timeframe}'") url = f"r/{subreddit}/search.json" data = self._fetch_data(url, params) return self._parse_posts(data) def get_new_subreddit_posts(self, subreddit: str, limit: int = 10) -> list[Post]: - posts = [] after = None url = f"r/{subreddit}/new.json" + logger.info(f"Fetching new posts from subreddit: {subreddit}") + while len(posts) < limit: batch_limit = min(100, limit - len(posts)) params = { @@ -45,6 +54,8 @@ class RedditAPI: data = self._fetch_data(url, params) batch = self._parse_posts(data) + logger.debug(f"Fetched {len(batch)} new posts from subreddit {subreddit}") + if not batch: break