Commit dd6b5fae authored by Bruno Duyé's avatar Bruno Duyé

Minor: bea_common.py format change

parent caf1cc5e
......@@ -6,9 +6,10 @@ APPENDIX_TO_DOWNLOAD = [
{
'code': 'NIPA',
'name': 'Appendix B – NIPA (National Income and Product Accounts)',
'cut_on_dimension': True,
'dimension_code': 'FREQ',
'dimension_label': 'Frequency',
'cut_on': {
'dimension_code': 'FREQ',
'dimension_label': 'Frequency',
},
'api': {
'datasets_list_url': 'https://bea.gov/api/data/?&UserID={api_user_id}&method=GetParameterValues&DataSetName={appendix_code}&ParameterName=TableName',
'dimensions_values_list_url': 'https://bea.gov/api/data/?&UserID={api_user_id}&method=GetParameterValues&DataSetName={appendix_code}&ParameterName=Frequency',
......@@ -19,9 +20,10 @@ APPENDIX_TO_DOWNLOAD = [
{
'code': 'NIUnderlyingDetail',
'name': 'Appendix C – NIUnderlyingDetail (National Income and Product Accounts)',
'cut_on_dimension': True,
'dimension_code': 'FREQ',
'dimension_label': 'Frequency',
'cut_on': {
'dimension_code': 'FREQ',
'dimension_label': 'Frequency',
},
'api': {
'datasets_list_url': 'https://bea.gov/api/data/?&UserID={api_user_id}&method=GetParameterValues&DataSetName={appendix_code}&ParameterName=TableName',
'dimensions_values_list_url': 'https://bea.gov/api/data/?&UserID={api_user_id}&method=GetParameterValues&DataSetName={appendix_code}&ParameterName=Frequency',
......@@ -32,7 +34,6 @@ APPENDIX_TO_DOWNLOAD = [
{
'code': 'FixedAssets',
'name': 'Appendix D – Fixed Assets',
'cut_on_dimension': False,
'api': {
# "TableID" is deprecated in API doc, but "TableName" is not supported here ...
'datasets_list_url': 'https://bea.gov/api/data/?&UserID={api_user_id}&method=GetParameterValues&DataSetName={appendix_code}&ParameterName=TableID',
......@@ -45,9 +46,10 @@ APPENDIX_TO_DOWNLOAD = [
{
'code': 'GDPbyIndustry',
'name': 'Appendix F – Gross Domestic Product by Industry (GDPbyIndustry)',
'cut_on_dimension': True,
'dimension_code': 'FREQ',
'dimension_label': 'Frequency',
'cut_on': {
'dimension_code': 'FREQ',
'dimension_label': 'Frequency',
},
'api': {
# "TableID" is deprecated in API doc, but "TableName" is not supported here ...
'datasets_list_url': 'https://bea.gov/api/data/?&UserID={api_user_id}&method=GetParameterValues&DataSetName={appendix_code}&ParameterName=TableID',
......@@ -72,9 +74,10 @@ APPENDIX_TO_DOWNLOAD = [
{
'code': 'UnderlyingGDPbyIndustry',
'name': 'Appendix L – Underlying Gross Domestic Product by Industry (UnderlyingGDPbyIndustry)',
'cut_on_dimension': True,
'dimension_code': 'FREQ',
'dimension_label': 'Frequency',
'cut_on': {
'dimension_code': 'FREQ',
'dimension_label': 'Frequency',
},
'api': {
'datasets_list_url': 'https://bea.gov/api/data/?&UserID={api_user_id}&method=GetParameterValues&DataSetName={appendix_code}&ParameterName=TableId',
'dimensions_values_list_url': 'https://bea.gov/api/data/?&UserID={api_user_id}&method=GetParameterValues&DataSetName={appendix_code}&ParameterName=Frequency',
......
......@@ -110,8 +110,8 @@ def main():
}))
datasets_json.append(toolz.valfilter(lambda e: e, { # filter None values
'dataset_code': dataset_code,
'dimension_label': appendix_dict['dimension_label'] if appendix_dict['cut_on_dimension'] else None,
'dimension_code': appendix_dict['dimension_code'] if appendix_dict['cut_on_dimension'] else None,
'dimension_label': toolz.get_in(['cut_on', 'dimension_label'], appendix_dict),
'dimension_code': toolz.get_in(['cut_on', 'dimension_code'], appendix_dict),
'files': dataset_json,
}))
# Write datasets.json
......@@ -125,7 +125,7 @@ def iter_data(dataset_code, appendix_dict):
=> in case of no "cut" on any dimension, dimension_value_code is None
"""
appendix_code = appendix_dict['code']
if appendix_dict['cut_on_dimension']:
if 'cut_on' in appendix_dict:
# Get list of dimensions_values to "cut" on
dimensions_values = get_from_api(appendix_dict['api']['dimensions_values_list_url'].format(
api_user_id=api_user_id, appendix_code=appendix_code))['ParamValue']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment