-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyth_parse.py
42 lines (33 loc) · 978 Bytes
/
pyth_parse.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
import json
import numpy as np
import matplotlib.pyplot as plt
from dateutil.parser import parse as dateParse
def main():
data = json.load(open('rates.json', 'r'))
headers = []
for d in data:
if d["currency"] in headers:
pass
else:
headers.append(d["currency"])
arranged_data = {}
l_h = []
plt.figure()
for header in headers:
arranged_data[header] = list(filter(lambda d: d["currency"] == header, data))
dates = []
rates = []
for d in arranged_data[header]:
try:
rates.append(float(d["rate"]))
dates.append(dateParse(d["date"]))
except:
pass
h, = plt.plot(dates, rates, label=header)
l_h.append(h)
with open('rates_rearranged.json', 'w') as outfile:
json.dump(arranged_data, outfile)
plt.legend(handles=l_h)
plt.show()
if __name__ == '__main__':
main()