-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget_ticker_list.py
More file actions
30 lines (21 loc) · 847 Bytes
/
get_ticker_list.py
File metadata and controls
30 lines (21 loc) · 847 Bytes
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
#! /usr/bin/env python
# encoding: utf-8
import urllib2
def download_file(url):
local_filename = url.split('/')[-1]
req = urllib2.Request(url)
response = urllib2.urlopen(req)
with open(local_filename, 'w') as f:
f.write(response.read())
return local_filename
def get_tickers(local_filename):
writer = open('tickers.txt', 'w')
with open(local_filename, 'r') as reader:
for line in reader:
if line.split('|')[0] != "Symbol" and \
"File Creation Time" not in line.split('|')[0]:
writer.write(line.split('|')[0] + "\n")
writer.close()
if __name__ == '__main__':
get_tickers(download_file('ftp://ftp.nasdaqtrader.com\
/SymbolDirectory/nasdaqlisted.txt'))