-
Notifications
You must be signed in to change notification settings - Fork 0
/
historicData.py
67 lines (53 loc) · 1.47 KB
/
historicData.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
# Kavin Autar
# 2013/11/19
# Version 1.0
# Checks stocks
import ystockquote as stock
import datetime
import logger as log
import json
import db
#Global vars
def getHistoricInfo(ycode):
code = ycode.split(".")[0]
#fromDay = "2000-01-01"
fromDay = "2013-11-21"
toDay = datetime.datetime.now().strftime("%Y-%m-%d")
log.info("getting historic [%s - %s] data for %s" % (fromDay, toDay, ycode))
try:
stockData = stock.get_historical_prices(ycode, fromDay, toDay)
except:
log.error("Unable to get historic data for %s" % ycode)
return None
historicDataQuery = """INSERT INTO HISTORIC_DATA
(DATE,
CODE,
HIGH,
LOW,
OPEN,
VOLUME)
VALUES (%s, %s, %s, %s, %s, %s);"""
days = stockData.keys()
for day in days:
date = str(day)
data = stockData[day]
# print data, type(data)
historicValues = [date,
code,
data['High'],
data['Low'],
data['Open'],
data['Volume']]
db.insertSingle(historicDataQuery, historicValues)
def main():
import sys
try:
code = sys.argv[1]
except:
print "No argument passed\n\nUsage\npython historicData.py CODE.SUFFIX\npython historicData.py CBA.ax"
log.error("historicData.py called with no argument")
import sys
sys.exit(1)
getHistoricInfo(code)
if __name__ == "__main__":
main()