init
This commit is contained in:
37
util/StockExtractor.py
Normal file
37
util/StockExtractor.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import json
|
||||
|
||||
class StockExtractor:
|
||||
|
||||
def __init__(self):
|
||||
return
|
||||
|
||||
def write (self, dir, code):
|
||||
inFile = open(dir+"/stock.json", 'r', encoding='utf-8')
|
||||
outFile = open(dir+"/"+code+".txt", 'w', encoding='utf-8')
|
||||
|
||||
outFile.write("DATE\tclose\tdiff\topen\thigh\tlow\tvolume\tavg3\tavg5\tavg7\tavg10\tavg20\tavg30\tavg60\tavg90\tavg100\tavg120\tavg150\tavg180\tavg200\tavg240\n")
|
||||
while True:
|
||||
line = inFile.readline()
|
||||
if not line:
|
||||
break
|
||||
|
||||
data = json.loads(line)
|
||||
if data['CODE'] == code:
|
||||
price = data['PRICE']
|
||||
for item in price:
|
||||
outFile.write("%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n"%(item["DATE"], item["close"], item["diff"], item["open"], item["high"], item["low"], item["volume"], item["avg3"], item["avg5"], item["avg7"], item["avg10"], item["avg20"], item["avg30"], item["avg60"], item["avg90"], item["avg100"], item["avg120"], item["avg150"], item["avg180"], item["avg200"], item["avg240"]))
|
||||
break
|
||||
|
||||
outFile.close()
|
||||
inFile.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
stockExtractor = StockExtractor()
|
||||
# "NAME": "KODEX 코스닥150선물인버스", "CODE": "251340"
|
||||
# "NAME": "KODEX 코스닥150 레버리지", "CODE": "233740"
|
||||
# "NAME": "KODEX 200선물인버스2X", "CODE": "252670"
|
||||
# "NAME": "KODEX 레버리지", "CODE": "122630"
|
||||
stockExtractor.write("../resources/", "251340")
|
||||
stockExtractor.write("../resources/", "233740")
|
||||
stockExtractor.write("../resources/", "252670")
|
||||
stockExtractor.write("../resources/", "122630")
|
||||
Reference in New Issue
Block a user