Initial code check in, generates basic graph

This commit is contained in:
meberlein committed 2019-02-17 14:30:46 -05:00
1 parent 081c7f3c6d
commit cc32722e8c
4 files changed
+113

No files matched your search

+1
View File
@@ -0,0 +1 @@
*.ini
+7
View File
@@ -0,0 +1,7 @@
<html><head><meta charset="utf-8" /></head><body><script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script><script type="text/javascript">/**
* plotly.js v1.44.3
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
* Licensed under the MIT license
*/
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Plotly=t()}}(function(){return function(){return function t(e,r,n){function i(o,s){if(!r[o]){if(!e[o]){var l="function"==typeof require&&require;if(!s&&l)return l(o,!0);if(a)return a(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var u=r[o]={exports:{}};e[o][0].call(u.exports,function(t){return i(e[o][1][t]||t)},u,u.exports,t,e,r,n)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}}()({1:[function(t,e,r){"use strict";var n=t("../src/lib"),i={"X,X div":"direction:ltr;font-family:'Open Sans', verdana, arial, sans-serif;margin:0;padding:0;","X input,X button":"font-family:'Open Sans', verdana, arial, sans-serif;","X input:focus,X button:focus":"outline:none;","X a":"text-decoration:none;","X a:hover":"text-decoration:none;","X .crisp":"shape-rendering:crispEdges;","X .user-select-none":"-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;","X svg":"overflow:hidden;","X svg a":"fill:#447adb;","X svg a:hover":"fill:#3c6dc5;","X .main-svg":"position:absolute;top:0;left:0;pointer-events:none;","X .main-svg .draglayer":"pointer-events:all;","X .cursor-default":"cursor:default;","X .cursor-pointer":"cursor:pointer;","X .cursor-crosshair":"cursor:crosshair;","X .cursor-move":"cursor:move;","X .cursor-col-resize":"cursor:col-resize;","X .cursor-row-resize":"cursor:row-resize;","X .cursor-ns-resize":"cursor:ns-resize;","X .cursor-ew-resize":"cursor:ew-resize;","X .cursor-sw-resize":"cursor:sw-resize;","X .cursor-s-resize":"cursor:s-resize;","X .cursor-se-resize":"cursor:se-resize;","X .cursor-w-resize":"cursor:w-resize;","X .cursor-e-resize":"cursor:e-resize;","X .cursor-nw-resize":"cursor:nw-resize;","X .cursor-n-resize":"cursor:n-resize;","X .cursor-ne-resize":"cursor:ne-resize;","X .cursor-grab":"cursor:-webkit-grab;cursor:grab;","X .modebar":"position:absolute;top:2px;right:2px;z-index:1001;","X .ease-bg":"-webkit-transition:background-color 0.3s ease 0s;-moz-transition:background-color 0.3s ease 0s;-ms-transition:background-color 0.3s ease 0s;-o-transition:background-color 0.3s ease 0s;transition:background-color 0.3s ease 0s;","X .modebar--hover>:not(.watermark)":"opacity:0;-webkit-transition:opacity 0.3s ease 0s;-moz-transition:opacity 0.3s ease 0s;-ms-transition:opacity 0.3s ease 0s;-o-transition:opacity 0.3s ease 0s;transition:opacity 0.3s ease 0s;","X:hover .modebar--hover .modebar-group":"opacity:1;","X .modebar-group":"float:left;display:inline-block;box-sizing:border-box;margin-left:8px;position:relative;vertical-align:middle;white-space:nowrap;","X .modebar-btn":"position:relative;font-size:16px;padding:3px 4px;height:22px;cursor:pointer;line-height:normal;box-sizing:border-box;","X .modebar-btn svg":"position:relative;top:2px;","X .modebar.vertical":"display:flex;flex-direction:column;flex-wrap:wrap;align-content:flex-end;max-height:100%;","X .modebar.vertical svg":"top:-1px;","X .modebar.vertical .modebar-group":"display:block;float:none;margin-left:0px;margin-bottom:8px;","X .modebar.vertical .modebar-group .modebar-btn":"display:block;text-align:center;","X [data-title]:before,X [data-title]:after":"position:absolute;-webkit-transform:translate3d(0, 0, 0);-moz-transform:translate3d(0, 0, 0);-ms-transform:translate3d(0, 0, 0);-o-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0);display:none;opacity:0;z-index:1001;pointer-events:none;top:110%;right:50%;","X [data-title]:hover:before,X [data-title]:hover:after":"display:block;opacity:1;","X [data-title]:before":"content:'';position:absolute;background:transparent;border:6px solid transparent;z-index:1002;margin-top:-12px;border-bottom-color:#69738a;margin-right:-6px;","X [data-title]:after":"content:attr(data-title);background:#69738a;color:white;padding:8px 10px;font-size:12px;line-height:12px;white-space:nowrap;margin-right:-18px;border-radius:2px;","X .vertical [data-title]:before,X .vertical [data-title]:after":"top:0%;right:200%;","X .vertical [data-title]:before":"border:6px solid transparent;border-left-color:#69738a;margin-top:8px;margin-right:-30px;","X .select-outline":"fill:none;stroke-width:1;shape-rendering:crispEdges;","X .select-outline-1":"stroke:white;","X .select-outline-2":"stroke:black;stroke-dasharray:2px 2px;",Y:"font-family:'Open Sans';position:fixed;top:50px;right:20px;z-index:10000;font-size:10pt;max-width:180px;","Y p":"margin:0;","Y .notifier-note":"min-width:180px;max-width:250px;border:1px solid #fff;z-index:3000;margin:0;background-color:#8c97af;background-color:rgba(140,151,175,0.9);color:#fff;padding:10px;overflow-wrap:break-word;word-wrap:break-word;-ms-hyphens:auto;-webkit-hyphens:auto;hyphens:auto;","Y .notifier-Line truncated
+94
View 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')
+11
View File
@@ -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=<APIKEY>