update User-agent header in _fetch_data method and add __exit__ method to Database class

This commit is contained in:
2026-01-11 15:30:34 +00:00
parent b5a2b01402
commit 195188dcd7
2 changed files with 6 additions and 2 deletions

View File

@@ -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:

View File

@@ -28,3 +28,7 @@ class Database:
def close(self):
self.connection.close()
print("Database connection closed.")
def __exit__(self, exc_type, exc_val, exc_tb):
self.close()