PATCH: Broken URL handling
This commit is contained in:
@@ -12,7 +12,7 @@ class RedditConnector(BaseConnector):
|
||||
'limit': limit,
|
||||
't': timeframe
|
||||
}
|
||||
url = f"{self.url}top.json"
|
||||
url = f"top.json"
|
||||
data = self._fetch_data(url, params)
|
||||
return self._parse_posts(data)
|
||||
|
||||
@@ -25,7 +25,7 @@ class RedditConnector(BaseConnector):
|
||||
'sort': 'relevance',
|
||||
't': 'day'
|
||||
}
|
||||
url = f"{self.url}search.json"
|
||||
url = f"search"
|
||||
data = self._fetch_data(url, params)
|
||||
return self._parse_posts(data)
|
||||
|
||||
@@ -60,7 +60,7 @@ class RedditConnector(BaseConnector):
|
||||
def _fetch_data(self, endpoint: str, params: dict) -> dict:
|
||||
url = f"{self.url}{endpoint}"
|
||||
try:
|
||||
response = requests.get(url, headers={'User-agent': 'your bot 0.1'}, params=params)
|
||||
response = requests.get(url, headers={'User-agent': 'python:myredditapp:0.1 (by /u/ThisBirchWood)'}, params=params)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except requests.RequestException as e:
|
||||
|
||||
2
main.py
2
main.py
@@ -3,7 +3,7 @@ from connectors.reddit_connector import RedditConnector
|
||||
if __name__ == "__main__":
|
||||
connector = RedditConnector()
|
||||
|
||||
search_results = connector.search_posts(search="NVIDIA", limit=10)
|
||||
search_results = connector.get_top_posts(limit=5, timeframe='week')
|
||||
for post in search_results:
|
||||
print(f"Title: {post.title}\nAuthor: {post.author}\nSubreddit: {post.subreddit}\nUpvotes: {post.upvotes}")
|
||||
print("---")
|
||||
Reference in New Issue
Block a user