yes-man-today
commited on
Commit
·
0024344
1
Parent(s):
d152bd8
basic fixes
Browse files- regulatory_comments_api.py +2 -53
regulatory_comments_api.py
CHANGED
@@ -90,58 +90,6 @@ class RegulationsDataFetcher:
|
|
90 |
else:
|
91 |
print(f'Failed to retrieve comment details: {response.status_code}')
|
92 |
return None
|
93 |
-
|
94 |
-
# def collect_data(self):
|
95 |
-
# """Collect data and reshape into nested dictionary format."""
|
96 |
-
# data = self.fetch_comments()
|
97 |
-
# if data is None:
|
98 |
-
# return None
|
99 |
-
|
100 |
-
# docket_info = self.get_docket_info()
|
101 |
-
# if docket_info is None:
|
102 |
-
# return None
|
103 |
-
|
104 |
-
# nested_data = {
|
105 |
-
# "id": self.docket_id,
|
106 |
-
# "agency": self.docket_id.split('-')[0],
|
107 |
-
# "title": docket_info[1] if docket_info else "Unknown Title",
|
108 |
-
# "update_date": docket_info[2].split('T')[0] if docket_info and docket_info[2] else "Unknown Update Date",
|
109 |
-
# "update_time": docket_info[2].split('T')[1].strip('Z') if docket_info and docket_info[2] and 'T' in docket_info[2] else "Unknown Update Time",
|
110 |
-
# "purpose": docket_info[3],
|
111 |
-
# "keywords": docket_info[4],
|
112 |
-
# "comments": []
|
113 |
-
# }
|
114 |
-
|
115 |
-
# if 'data' in data:
|
116 |
-
# for comment in data['data']:
|
117 |
-
# comment_details = self.fetch_comment_details(comment['links']['self'])
|
118 |
-
|
119 |
-
# # Here, we extra information and perform cleaning.
|
120 |
-
# if 'data' in comment_details and 'attributes' in comment_details['data']:
|
121 |
-
# comment_data = comment_details['data']['attributes']
|
122 |
-
# comment_text = (comment_data.get('comment', '') or '').strip()
|
123 |
-
# comment_text = (comment_text # Doing some extra cleaning
|
124 |
-
# .replace("<br/>", "")
|
125 |
-
# .replace("<span style='padding-left: 30px'></span>", "")
|
126 |
-
# .replace(re.sub(r'&[^;]+;', '', comment_text)))
|
127 |
-
|
128 |
-
# if (comment_text and "attached" not in comment_text.lower() and "attachment" not in comment_text.lower() and comment_text.lower() != "n/a"):
|
129 |
-
# nested_comment = {
|
130 |
-
# "text": comment_text,
|
131 |
-
# "comment_id": comment['id'],
|
132 |
-
# "comment_url": comment['links']['self'],
|
133 |
-
# "comment_date": comment['attributes']['postedDate'].split('T')[0],
|
134 |
-
# "comment_time": comment['attributes']['postedDate'].split('T')[1].strip('Z'),
|
135 |
-
# "commenter_fname": ((comment_data.get('firstName') or 'Anonymous').split(',')[0]).capitalize(),
|
136 |
-
# "commenter_lname": ((comment_data.get('lastName') or 'Anonymous').split(',')[0]).capitalize(),
|
137 |
-
# "comment_length": len(comment_text) if comment_text is not None else 0
|
138 |
-
# }
|
139 |
-
# nested_data["comments"].append(nested_comment)
|
140 |
-
|
141 |
-
# if len(nested_data["comments"]) >= 10:
|
142 |
-
# break
|
143 |
-
|
144 |
-
# return nested_data
|
145 |
|
146 |
def collect_data(self):
|
147 |
"""Collect data and reshape into nested dictionary format."""
|
@@ -165,7 +113,7 @@ class RegulationsDataFetcher:
|
|
165 |
"comments": []
|
166 |
}
|
167 |
|
168 |
-
#
|
169 |
if 'data' in data:
|
170 |
for comment in data['data']:
|
171 |
if len(nested_data["comments"]) >= 10:
|
@@ -180,6 +128,7 @@ class RegulationsDataFetcher:
|
|
180 |
comment_text = comment_text.replace("<br/>", "").replace("<span style='padding-left: 30px'></span>", "")
|
181 |
comment_text = re.sub(r'&[^;]+;', '', comment_text)
|
182 |
|
|
|
183 |
if (comment_text and "attached" not in comment_text.lower() and "attachment" not in comment_text.lower() and comment_text.lower() != "n/a"):
|
184 |
nested_comment = {
|
185 |
"text": comment_text,
|
|
|
90 |
else:
|
91 |
print(f'Failed to retrieve comment details: {response.status_code}')
|
92 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
def collect_data(self):
|
95 |
"""Collect data and reshape into nested dictionary format."""
|
|
|
113 |
"comments": []
|
114 |
}
|
115 |
|
116 |
+
# Going into each docket for comment information
|
117 |
if 'data' in data:
|
118 |
for comment in data['data']:
|
119 |
if len(nested_data["comments"]) >= 10:
|
|
|
128 |
comment_text = comment_text.replace("<br/>", "").replace("<span style='padding-left: 30px'></span>", "")
|
129 |
comment_text = re.sub(r'&[^;]+;', '', comment_text)
|
130 |
|
131 |
+
# Recording detailed comment information
|
132 |
if (comment_text and "attached" not in comment_text.lower() and "attachment" not in comment_text.lower() and comment_text.lower() != "n/a"):
|
133 |
nested_comment = {
|
134 |
"text": comment_text,
|