yes-man-today
commited on
Commit
·
cf669b7
1
Parent(s):
904abf8
incorporate api key in kwargs
Browse files- regulatory_comments_api.py +13 -12
regulatory_comments_api.py
CHANGED
@@ -34,23 +34,22 @@ _HOMEPAGE = "https://www.regulations.gov/"
|
|
34 |
_URLS = {"url": "https://huggingface.co/datasets/ro-h/regulatory_comments/raw/main/docket_comments_all.json"}
|
35 |
|
36 |
class RegulationsDataFetcher:
|
37 |
-
API_KEY = "IsH1c1CAB0CR8spovnnx2INbLz8gQlVkbmXYII2z" #'4T29l93SvmnyNCVFZUFzSfUqTq6k7S0Wqn93sLcH'
|
38 |
BASE_COMMENT_URL = 'https://api.regulations.gov/v4/comments'
|
39 |
BASE_DOCKET_URL = 'https://api.regulations.gov/v4/dockets/'
|
40 |
-
HEADERS = {
|
41 |
-
'X-Api-Key': API_KEY,
|
42 |
-
'Content-Type': 'application/json'
|
43 |
-
}
|
44 |
|
45 |
-
def __init__(self, docket_id):
|
46 |
self.docket_id = docket_id
|
|
|
47 |
self.docket_url = self.BASE_DOCKET_URL + docket_id
|
48 |
-
self.
|
|
|
|
|
|
|
49 |
|
50 |
def fetch_comments(self):
|
51 |
"""Fetch a single page of 25 comments."""
|
52 |
url = f'{self.BASE_COMMENT_URL}?filter[docketId]={self.docket_id}&page[number]=1&page[size]=25'
|
53 |
-
response = requests.get(url, headers=self.
|
54 |
|
55 |
if response.status_code == 200:
|
56 |
return response.json()
|
@@ -60,7 +59,7 @@ class RegulationsDataFetcher:
|
|
60 |
|
61 |
def get_docket_info(self):
|
62 |
"""Get docket information."""
|
63 |
-
response = requests.get(self.docket_url, headers=self.
|
64 |
|
65 |
if response.status_code == 200:
|
66 |
docket_data = response.json()
|
@@ -72,10 +71,11 @@ class RegulationsDataFetcher:
|
|
72 |
else:
|
73 |
print(f'Failed to retrieve docket info: {response.status_code}')
|
74 |
return None
|
75 |
-
|
76 |
def fetch_comment_details(self, comment_url):
|
77 |
"""Fetch detailed information of a comment."""
|
78 |
-
response = requests.get(comment_url, headers=self.
|
|
|
79 |
if response.status_code == 200:
|
80 |
return response.json()
|
81 |
else:
|
@@ -119,6 +119,7 @@ class RegulationsDataFetcher:
|
|
119 |
break
|
120 |
|
121 |
return nested_data
|
|
|
122 |
|
123 |
class RegCommentsAPIConfig(BuilderConfig):
|
124 |
def __init__(self, api_key=None, **kwargs):
|
@@ -186,7 +187,7 @@ class RegCommentsAPI(datasets.GeneratorBasedBuilder):
|
|
186 |
# Iterate over each search term to fetch relevant dockets
|
187 |
for term in search_terms:
|
188 |
docket_ids = get_docket_ids(term, api_key) # Pass the API key here
|
189 |
-
|
190 |
for docket_id in docket_ids:
|
191 |
fetcher = RegulationsDataFetcher(docket_id, api_key) # Initialize with the API key
|
192 |
docket_data = fetcher.collect_data()
|
|
|
34 |
_URLS = {"url": "https://huggingface.co/datasets/ro-h/regulatory_comments/raw/main/docket_comments_all.json"}
|
35 |
|
36 |
class RegulationsDataFetcher:
|
|
|
37 |
BASE_COMMENT_URL = 'https://api.regulations.gov/v4/comments'
|
38 |
BASE_DOCKET_URL = 'https://api.regulations.gov/v4/dockets/'
|
|
|
|
|
|
|
|
|
39 |
|
40 |
+
def __init__(self, docket_id, api_key):
|
41 |
self.docket_id = docket_id
|
42 |
+
self.api_key = api_key
|
43 |
self.docket_url = self.BASE_DOCKET_URL + docket_id
|
44 |
+
self.headers = {
|
45 |
+
'X-Api-Key': self.api_key,
|
46 |
+
'Content-Type': 'application/json'
|
47 |
+
}
|
48 |
|
49 |
def fetch_comments(self):
|
50 |
"""Fetch a single page of 25 comments."""
|
51 |
url = f'{self.BASE_COMMENT_URL}?filter[docketId]={self.docket_id}&page[number]=1&page[size]=25'
|
52 |
+
response = requests.get(url, headers=self.headers)
|
53 |
|
54 |
if response.status_code == 200:
|
55 |
return response.json()
|
|
|
59 |
|
60 |
def get_docket_info(self):
|
61 |
"""Get docket information."""
|
62 |
+
response = requests.get(self.docket_url, headers=self.headers)
|
63 |
|
64 |
if response.status_code == 200:
|
65 |
docket_data = response.json()
|
|
|
71 |
else:
|
72 |
print(f'Failed to retrieve docket info: {response.status_code}')
|
73 |
return None
|
74 |
+
|
75 |
def fetch_comment_details(self, comment_url):
|
76 |
"""Fetch detailed information of a comment."""
|
77 |
+
response = requests.get(comment_url, headers=self.headers)
|
78 |
+
|
79 |
if response.status_code == 200:
|
80 |
return response.json()
|
81 |
else:
|
|
|
119 |
break
|
120 |
|
121 |
return nested_data
|
122 |
+
|
123 |
|
124 |
class RegCommentsAPIConfig(BuilderConfig):
|
125 |
def __init__(self, api_key=None, **kwargs):
|
|
|
187 |
# Iterate over each search term to fetch relevant dockets
|
188 |
for term in search_terms:
|
189 |
docket_ids = get_docket_ids(term, api_key) # Pass the API key here
|
190 |
+
|
191 |
for docket_id in docket_ids:
|
192 |
fetcher = RegulationsDataFetcher(docket_id, api_key) # Initialize with the API key
|
193 |
docket_data = fetcher.collect_data()
|