-
Notifications
You must be signed in to change notification settings - Fork 4
/
shelfdata.py
61 lines (47 loc) · 1.4 KB
/
shelfdata.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
import shelve
from csvdata import *
class shelve_data:
def __init__(self, input_file):
self.file = input_file
self.data = shelve.open(self.file)
pass
def read(self, date):
try:
return self.data[date]
except KeyError:
return None
def add(self, date, data):
self.data[date] = data
def range(self):
return self.data['range']
def newest_date(self):
return self.data['range'][0]
def oldest_date(self):
return self.data['range'][1]
def newest(self):
try:
return self.data[self.newest_date()]
except KeyError:
return None
def __iter__(self):
return self
def next(self):
pass
def conv_from_csv(self, csvfile):
csv_data = csvdata(csvfile)
csv_data.read()
maxdate = None
mindate = None
for data in csv_data.data.values():
print data
self.add(data[0], data)
if data[0] > maxdate or maxdate == None:
maxdate = data[0]
if data[0] < mindate or mindate == None:
mindate = data[0]
print "MaxDate: " + maxdate + " MinDate: " + mindate
self.data['range'] = [maxdate, mindate]
self.data.close()
ttt = shelve_data('/tmp/shelve_data_test')
#ttt.conv_from_csv('/tmp/stock.csv')
print ttt.read('2015-11-27')