-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
70 lines (51 loc) · 1.72 KB
/
plot.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
#!/usr/bin/env python3
import json
from datetime import datetime
from datetime import timedelta
import numpy as np
import matplotlib.pyplot as plt
import gzip
import time
import esi_calling
try:
with gzip.GzipFile('market_cache.gz', 'r') as fin:
market_cache = json.loads(fin.read().decode('utf-8'))
except:
print('no market cache found')
market_cache = {}
try:
with gzip.GzipFile('item_cache.gz', 'r') as fin:
item_cache = json.loads(fin.read().decode('utf-8'))
except:
print('no item_cache found')
item_cache = {}
def plot_prices(item_id):
#market_cache[str(item_id)]['buy_prices']
if str(item_id) in market_cache:
times = []
for time in market_cache[str(item_id)]['times']:
times.append(datetime.strptime(time, '%Y-%m-%d %H:%M:%S'))
plt.plot(times, market_cache[str(item_id)]['buy_prices'], 'r-', label='Buy prices')
plt.plot(times, market_cache[str(item_id)]['sell_prices'], 'b-', label='Sell prices')
plt.gcf().autofmt_xdate()
plt.title(item_cache[str(item_id)]['name'])
plt.xlabel('Time')
plt.ylabel('Price')
plt.legend(loc='best')
plt.grid(True)
plt.show()
else:
print('No data for "'+ item_id+ '"')
while True:
text = input("Give type ID: ")
if not text in item_cache:
print( 'Fetching info on ID "'+ text+'"')
response = esi_calling.call_esi(scope = '/v3/universe/types/{par}/', url_parameters=[text], job = 'get item info')[0][0]
if response.status_code != 200:
print( 'No item with ID "'+ text+'"')
continue
else:
item_cache[text] = response.json()
with gzip.GzipFile('item_cache.gz', 'w') as outfile:
outfile.write(json.dumps(item_cache).encode('utf-8'))
plot_prices(text)