-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqmscrape.py
executable file
·55 lines (45 loc) · 1.75 KB
/
qmscrape.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
#!/usr/bin/env python
'''
Caution: This scraper only returns dividend adjusted closing prices and cannot
be expected to agree with the others
'''
import urllib2
import csv
from scraperutil import *
def gethistory(symbol):
_atonce = 300
end = endtime()
start = end - datetime.timedelta(_atonce)
urltemplate = 'http://app.quotemedia.com/quotetools/getHistoryDownload.csv?&webmasterId=501&startDay={startday}&startMonth={startmonth}&startYear={startyear}&endDay={endday}&endMonth={endmonth}&endYear={endyear}&isRanged=false&symbol={symbol}'
fulllist = []
dates = set()
while True:
url = urltemplate.format(symbol=symbol,
endday=end.day,
endmonth=end.month,
endyear=end.year,
startday=start.day,
startmonth=start.month,
startyear=start.year)
alldupe = True
for line in csv.DictReader(urllib2.urlopen(url)):
date = line['date']
if date not in dates:
alldupe = False
dates.add(date)
newline = {}
try:
date = formatdate(line['date'], '%Y-%m-%d')
except ValueError:
continue
newline['Date'] = date
newline['Open'] = round(float(line['open']), 2)
newline['Close'] = round(float(line['close']), 2)
fulllist.append(newline)
if alldupe:
break
(start, end) = (start - datetime.timedelta(_atonce), start)
return fulllist
if __name__ == "__main__":
import sys
printdata(gethistory(sys.argv[1]))