-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymbolSourceEOD.py
executable file
·51 lines (42 loc) · 1.12 KB
/
SymbolSourceEOD.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
#!/usr/bin/python
import httplib2
from bs4 import BeautifulSoup
class SymbolSourceEOD:
def __init__(self):
self.link = 'http://eoddata.com/stocklist/USMF/'
self.rang = range(ord('A'), ord('Z')+1)
def getSymbols(self):
allSymbols = list()
for i in self.rang:
l = self.link + chr(i) + '.htm'
print 'processing: ', l
content = self._getHtml(l)
symbols = self._parseSymbols(content)
allSymbols.extend(symbols)
return allSymbols
def _getHtml(self, link):
try:
h = httplib2.Http()
response, content = h.request(link, 'GET',)
return content
except KeyboardInterrupt:
raise KeyboardInterrupt
def _parseSymbols(self, content):
data = list()
soup = BeautifulSoup(content)
p = soup.find('table', {'class' : 'quotes'})
s = p.find('tr')
lines = s.findNextSiblings('tr')
for line in lines:
fund = dict()
symbol = line.find('td')
cells = symbol.findNextSiblings('td')
fund['sym'] = str(symbol.text)
fund['des'] = str(cells[0].text)
data.append(fund)
return data
# unit test
if __name__ == '__main__':
from pprint import pprint
c = SymbolSourceEOD()
pprint(c.getSymbols())