/
tickerlist.py
54 lines (49 loc) · 1.86 KB
/
tickerlist.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
#!/usr/bin/env python
import screens
import random
from screens import make_finviz_url
import utils
from utils import get_pretty_html
from utils import find_between
from check_ticker_age import is_old_enough
from check_ticker_age import get_ticker_article_age
import os
pwd = os.path.dirname(__file__)
article_path = pwd + "/Articles"
excluded_tickers = ['AAPL','AUTH','BMA','CRED','CSCO','CTEL','CVX','DMF',
'DSM','EFC','FB','FCX','LEO','MCC',
'MTGE','PEET','TGS']
class TickerList:
def __init__(self, screen ):
self.screen = screen
pending_tickers = self.get_pending_tickers()
url = make_finviz_url( screen )
pretty_html = get_pretty_html( url )
self.tickers = []
counter = 0
max_len = random.randrange(6, 7)
while find_between( pretty_html, '<a href="quote.ashx?t=', '&' ):
if counter > max_len:
break
ticker = find_between( pretty_html, '<a href="quote.ashx?t=', '&' )
pretty_html = pretty_html.replace('<a href="quote.ashx?t=','',1)
if ticker in pending_tickers:
continue
if ticker in excluded_tickers:
continue
print "testing ticker " + ticker
# only take tickers older than 25 days
age = get_ticker_article_age( ticker )
if is_old_enough( age ):
self.tickers.append( ticker )
counter = counter + 1
def get_pending_tickers(self):
f = open( article_path + '/tickers.txt','a+' )
pending_tickers = filter( None, f.read().split(',') )
f.close()
return pending_tickers
def update_pending_tickers(self):
f = open( article_path + '/tickers.txt','a+' )
f.write( ','.join( self.tickers ) + ',' )
f.close()
return True