def get_category_documents(category, document_type, results_per_page, comments_open):
"""
Get a list of documents in a particular category
Explanation of additional parameters used in API query:
- cp: comment period. Set to O (Open)
- cs: comment period closing soon. Set to 90 (days until closing)
:param str category: Category of docket. One of the keys to REGULATION_CATEGORIES stored in constants.py
:param str document_type: One of N: Notice, PR: Proposed Rule, FR: Rule, O: Other, SR: Supporting & Related Material
PS: Public Submission
:param int results_per_page: Number of records to return per query (since we're not doing a paged query).
:param bool comments_open: Return results that have comments open or not
:return: A JSON object containing 'documents', a list of document records returned by the API and an added
'category' field.
"""
# The results per page search parameter can only take the following values
rpp = min(r for r in [10, 25, 100, 500, 1000] if r > results_per_page)
search_parameters = {'api_key': REG_API_KEY,
'cat': category,
'dct': document_type,
'rpp': rpp}
if comments_open:
search_parameters['cp'] = 'O'
search_parameters['cs'] = 90
else:
search_parameters['cp'] = 'C'
fetched_dockets = requests.get('https://api.data.gov/regulations/v3/documents', params=search_parameters)
dockets_obj = fetched_dockets.json()
return dockets_obj
评论列表
文章目录