/
cxStockMgr.py
114 lines (88 loc) · 2.94 KB
/
cxStockMgr.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
################################################################################
# -*- coding: utf-8 -*-
# author : Jinwon Oh
# file name : cxStockMgr.py
# date : 2012-10-01 19:07:23
# ver :
# desc. :
# tab size : set sw=4, ts=4
# python ver. : 2.7.1 Stackless 3.1b3 060516 (release27-maint, Jan 1 2011, 13:04:37) [MSC v.1500 32 bit (Intel)]
# ADD CODES FROM HERE
from cxCybosPlus import cxCpStockCode
import codecs
import time
class cxStockMgr :
def __init__(self) :
self.stockList = []
def __del__(self) :
pass
def update(self) :
del self.stockList
self.stockList = []
try :
cpStockCode = cxCpStockCode()
except : return -1
stockNum = cpStockCode.GetCount()
for i in range( 0, stockNum ) :
stockItem = []
stockItem.append( cpStockCode.GetData( 0, i ) ) # stockCode
stockItem.append( cpStockCode.GetData( 1, i ) ) # stockName
stockItem.append( cpStockCode.GetData( 2, i ) ) # stockFullCode
self.stockList.append( stockItem )
del cpStockCode
return len( self.stockList)
def dump(self) :
dumpString = u''
for i in range( 0, len( self.stockList ) ) :
dumpString += self.stockList[i][0] + u'\t'
dumpString += self.stockList[i][2] + u'\t'
dumpString += self.stockList[i][1] + u'\n'
return dumpString
def searchStockCode(self, stockName ) :
stockNum = len( self.stockList )
if stockNum <= 0 : return []
resultList = []
for i in range( 0, stockNum ) :
if self.stockList[i][1].find( stockName ) >= 0 :
resultList.append( [ self.stockList[i][0], self.stockList[i][1] ] )
return resultList
def getStockList(self) :
return self.stockList
def test_findStock() :
stockMgr = cxStockMgr()
if stockMgr.update() > 0 :
for result in stockMgr.searchStockCode( u'현대') :
print result[0], result[1]
del stockMgr
def test_01() :
from cxFile import cxFile
resultFile = cxFile()
stockMgr = cxStockMgr()
if stockMgr.update() > 0 :
resultFile.write(stockMgr.dump())
#for result in stockMgr.searchStockCode( u'삼성' ) :
# print result[0], result[1]
resultFile.close()
del stockMgr
def test() :
test_findStock()
def collect_and_show_garbage() :
"Show what garbage is present."
print "Collecting..."
n = gc.collect()
print "Unreachable objects:", n
if n > 0 : print "Garbage:"
for i in range(n):
print "[%d] %s" % (i, gc.garbage[i])
if __name__ == "__main__" :
import gc
gc.set_debug(gc.DEBUG_LEAK)
print "before"
collect_and_show_garbage()
print "testing..."
print "-"*79
test()
print "-"*79
print "after"
collect_and_show_garbage()
raw_input("Hit any key to close this window...")