From 195188dcd7d8b96cdf358e4bfb1c018da26bd6e9 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Sun, 11 Jan 2026 15:30:34 +0000 Subject: [PATCH] update User-agent header in _fetch_data method and add __exit__ method to Database class --- connectors/reddit_connector.py | 2 +- db/database.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/connectors/reddit_connector.py b/connectors/reddit_connector.py index 3a9c761..fa701ea 100644 --- a/connectors/reddit_connector.py +++ b/connectors/reddit_connector.py @@ -91,7 +91,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': 'python:myredditapp:0.1 (by /u/ThisBirchWood)'}, params=params) + response = requests.get(url, headers={'User-agent': 'python:ethnography-college-project:0.1 (by /u/ThisBirchWood)'}, params=params) response.raise_for_status() return response.json() except requests.RequestException as e: diff --git a/db/database.py b/db/database.py index ea2b5a6..4593ec4 100644 --- a/db/database.py +++ b/db/database.py @@ -27,4 +27,8 @@ class Database: cursor.executemany(query, params_list) def close(self): - self.connection.close() \ No newline at end of file + self.connection.close() + print("Database connection closed.") + + def __exit__(self, exc_type, exc_val, exc_tb): + self.close() \ No newline at end of file