Initial code check in, generates basic graph
This commit is contained in:
parent
081c7f3c6d
commit
cc32722e8c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
*.ini
|
||||||
7
CarOutPut_20190217.html
Normal file
7
CarOutPut_20190217.html
Normal file
File diff suppressed because one or more lines are too long
94
CarOutput_BEA.py
Normal file
94
CarOutput_BEA.py
Normal file
|
|
@ -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')
|
||||||
Loading…
Reference in New Issue
Block a user