update User-agent header in _fetch_data method and add __exit__ method to Database class
This commit is contained in:
@@ -91,7 +91,7 @@ class RedditConnector(BaseConnector):
|
|||||||
def _fetch_data(self, endpoint: str, params: dict) -> dict:
|
def _fetch_data(self, endpoint: str, params: dict) -> dict:
|
||||||
url = f"{self.url}{endpoint}"
|
url = f"{self.url}{endpoint}"
|
||||||
try:
|
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()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
|
|||||||
@@ -27,4 +27,8 @@ class Database:
|
|||||||
cursor.executemany(query, params_list)
|
cursor.executemany(query, params_list)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
|
print("Database connection closed.")
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
self.close()
|
||||||
Reference in New Issue
Block a user