diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d2127d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.ini diff --git a/CarOutPut_20190217.html b/CarOutPut_20190217.html new file mode 100644 index 0000000..76e0a89 --- /dev/null +++ b/CarOutPut_20190217.html @@ -0,0 +1,7 @@ +
\ No newline at end of file diff --git a/CarOutput_BEA.py b/CarOutput_BEA.py new file mode 100644 index 0000000..7bbaab6 --- /dev/null +++ b/CarOutput_BEA.py @@ -0,0 +1,94 @@ +from collections import OrderedDict +from time import sleep +from datetime import datetime +import json +import plotly.offline +import plotly.graph_objs as go +import requests +import configparser + +config = configparser.ConfigParser() +config.read('config.ini') +bea_server="https://apps.bea.gov/api/data" + +if config['DEFAULT']['APIKEY'] is not None: + bea_api_key=config['DEFAULT']['APIKEY'] +else: + print("You must supply an api key in a config.ini") + exit() + +args={"UserID":bea_api_key,"method":"GETDATASETLIST"} +dataSetListResponse=requests.get(bea_server,params=args) +dataSetListJSON=dataSetListResponse.json() +#print(json.dumps(dataSetListJSON,sort_keys=True,indent=4)) + +args["method"]="GetParameterList" +args["datasetname"]="NIPA" +parameterListResponse=requests.get(bea_server,params=args) +parameterListJSON=parameterListResponse.json() +#print(json.dumps(parameterListJSON,sort_keys=True,indent=4)) + + +args["method"]="GetParameterValues" +args["ParameterName"]="TableName" +paramaterValuesResponse=requests.get(bea_server,params=args) +paramaterValuesJSON=paramaterValuesResponse.json() +print(json.dumps(paramaterValuesJSON,sort_keys=True,indent=4)) + +#args["ParameterName"]="Year" +#paramaterValuesResponse=requests.get(bea_server,params=args) +#paramaterValuesJSON=paramaterValuesResponse.json() +#print(json.dumps(paramaterValuesJSON,sort_keys=True,indent=4)) + +motorVehicleOutput={} +autoOutput={} +truckOutput={} + +tableNames=["T70203A","T70203B"] +for table in tableNames: + args["TableName"]=table + args["method"]="GetData" + args["Frequency"]="Q" + args["ShowMillions"]="Y" + args["Year"]="X" + #",".join(map(str,range(2000,2018))) + tableResponse=requests.get(bea_server,params=args) + tableResponseJSON=tableResponse.json() + print(json.dumps(tableResponseJSON,sort_keys=True,indent=4)) + for item in tableResponseJSON["BEAAPI"]["Results"]["Data"]: + #print(item) + if item["LineDescription"]=="Motor vehicle output": + motorVehicleOutput[str(item["TimePeriod"]).lower()]=item["DataValue"] + elif item["LineDescription"]=="Auto output": + autoOutput[str(item["TimePeriod"]).lower()]=item["DataValue"] + elif item["LineDescription"]=="Truck output": + truckOutput[str(item["TimePeriod"]).lower()]=item["DataValue"] + + sleep(10) + +motorVehicleOutputSorted=OrderedDict(sorted(motorVehicleOutput.items())) +autoOutputSorted=OrderedDict(sorted(autoOutput.items())) +truckOutputSorted=OrderedDict(sorted(truckOutput.items())) + +print(motorVehicleOutputSorted) + +traceMotorVehicle=go.Scatter( + name="Motor Vehicle Output", + x=list(motorVehicleOutputSorted.keys()), + y=list(motorVehicleOutputSorted.values()) +) + +traceAuto=go.Scatter( + name="Auto Output", + x=list(autoOutputSorted.keys()), + y=list(autoOutputSorted.values()) +) + +traceTruck=go.Scatter( + name="Truck Output", + x=list(truckOutputSorted.keys()), + y=list(truckOutputSorted.values()) +) +data=[traceAuto, traceMotorVehicle,traceTruck] + +plotly.offline.plot(data,filename='CarOutPut_'+datetime.now().strftime('%Y%m%d')+'.html') \ No newline at end of file diff --git a/README.md b/README.md index c43b232..ee8713d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # CarOutput_BEA +This generates a graph of the BEA data for automobile output, motor vehicle output and truck output. + +Source: https://apps.bea.gov/api/data + +API key must be provided through a config.ini file. + +Format: + [DEFAULT] + APIKEY=