forked from datasets/oil-prices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oil_prices_flow.py
178 lines (169 loc) · 5.99 KB
/
oil_prices_flow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
from dataflows import (
Flow,
PackageWrapper,
validate,
)
from dataflows import add_metadata, dump_to_path, load, set_type, printer
def rename_resources(package: PackageWrapper):
package.pkg.descriptor["resources"][0]["name"] = "brent-daily"
package.pkg.descriptor["resources"][0]["path"] = "data/brent-daily.csv"
package.pkg.descriptor["resources"][1]["name"] = "brent-week"
package.pkg.descriptor["resources"][1]["path"] = "data/brent-weekly.csv"
package.pkg.descriptor["resources"][2]["name"] = "brent-month"
package.pkg.descriptor["resources"][2]["path"] = "data/brent-monthly.csv"
package.pkg.descriptor["resources"][3]["name"] = "brent-year"
package.pkg.descriptor["resources"][3]["path"] = "data/brent-year.csv"
package.pkg.descriptor["resources"][4]["name"] = "wti-daily"
package.pkg.descriptor["resources"][4]["path"] = "data/wti-daily.csv"
package.pkg.descriptor["resources"][5]["name"] = "wti-week"
package.pkg.descriptor["resources"][5]["path"] = "data/wti-weekly.csv"
package.pkg.descriptor["resources"][6]["name"] = "wti-month"
package.pkg.descriptor["resources"][6]["path"] = "data/wti-monthly.csv"
package.pkg.descriptor["resources"][7]["name"] = "wti-year"
package.pkg.descriptor["resources"][7]["path"] = "data/wti-year.csv"
yield package.pkg
res_iter = iter(package)
for res in res_iter:
yield res.it
yield from package
def filter_out_empty_rows(rows):
for row in rows:
if row["Date"]:
yield row
OIL_PRICES = Flow(
add_metadata(
name="oil-prices",
title="Brent and WTI Spot Prices",
descriptor=(
"A variety of temporal granularities for Europe Brent and WTI "
"(West Texas Intermediate) Spot Prices."
),
sources=[
{
"name": "Daily Europe Brent Spot Price",
"path": "https://www.eia.gov/dnav/pet/hist_xls/RBRTEd.xls",
"title": "Daily Europe Brent Spot Price",
},
{
"name": "Weekly Europe Brent Spot Price",
"path": "https://www.eia.gov/dnav/pet/hist_xls/RBRTEw.xls",
"title": "Weekly Europe Brent Spot Price",
},
{
"name": "Monthly Europe Brent Spot Price",
"path": "https://www.eia.gov/dnav/pet/hist_xls/RBRTEm.xls",
"title": "Monthly Europe Brent Spot Price",
},
{
"name": "Annual Europe Brent Spot Price",
"path": "https://www.eia.gov/dnav/pet/hist_xls/RBRTEa.xls",
"title": "Annual Europe Brent Spot Price",
},
{
"name": "Daily Cushing, OK WTI Spot Price",
"path": "http://www.eia.gov/dnav/pet/hist_xls/RWTCd.xls",
"title": "Daily Cushing, OK WTI Spot Price",
},
{
"name": "Weekly Cushing, OK WTI Spot Price",
"path": "http://www.eia.gov/dnav/pet/hist_xls/RWTCw.xls",
"title": "Weekly Cushing, OK WTI Spot Price",
},
{
"name": "Monthly Cushing, OK WTI Spot Price",
"path": "http://www.eia.gov/dnav/pet/hist_xls/RWTCm.xls",
"title": "Monthly Cushing, OK WTI Spot Price",
},
{
"name": "Annual Cushing, OK WTI Spot Price",
"path": "http://www.eia.gov/dnav/pet/hist_xls/RWTCa.xls",
"title": "Annual Cushing, OK WTI Spot Price",
},
],
licenses=[
{
"name": "ODC-PDDL-1.0",
"path": "http://opendatacommons.org/licenses/pddl/",
"title": "Open Data Commons Public Domain Dedication and License v1.0",
}
],
keywords=["Oil", "Brent", "WTI", "Oil Prices", "eia", "oil eia"],
views=[
{
"name": "graph",
"title": "Europe Brent Spot Price FOB (Dollars per Barrel)",
"resourceName": "brent-day",
"specType": "simple",
"spec": {
"type": "line",
"group": "Date",
"series": ["Brent Spot Price"],
},
}
],
),
load(
load_source="https://www.eia.gov/dnav/pet/hist_xls/RBRTEd.xls",
format="xls",
sheet=2,
skip_rows=[1, 2, 3],
headers=["Date", "Price"],
),
load(
load_source="https://www.eia.gov/dnav/pet/hist_xls/RBRTEw.xls",
format="xls",
sheet=2,
skip_rows=[1, 2, 3],
headers=["Date", "Price"],
),
load(
load_source="https://www.eia.gov/dnav/pet/hist_xls/RBRTEm.xls",
format="xls",
sheet=2,
skip_rows=[1, 2, 3],
headers=["Date", "Price"],
),
load(
load_source="https://www.eia.gov/dnav/pet/hist_xls/RBRTEa.xls",
format="xls",
sheet=2,
skip_rows=[1, 2, 3],
headers=["Date", "Price"],
),
load(
load_source="http://www.eia.gov/dnav/pet/hist_xls/RWTCd.xls",
format="xls",
sheet=2,
skip_rows=[1, 2, 3],
headers=["Date", "Price"],
),
load(
load_source="http://www.eia.gov/dnav/pet/hist_xls/RWTCw.xls",
format="xls",
sheet=2,
skip_rows=[1, 2, 3],
headers=["Date", "Price"],
),
load(
load_source="http://www.eia.gov/dnav/pet/hist_xls/RWTCm.xls",
format="xls",
sheet=2,
skip_rows=[1, 2, 3],
headers=["Date", "Price"],
),
load(
load_source="http://www.eia.gov/dnav/pet/hist_xls/RWTCa.xls",
format="xls",
sheet=2,
skip_rows=[1, 2, 3],
headers=["Date", "Price"],
),
rename_resources,
set_type("Date", resources=None, type="date", format="any"),
validate(),
printer(),
filter_out_empty_rows,
dump_to_path(),
)
if __name__ == "__main__":
OIL_PRICES.process()