/
pyticker.py
executable file
·81 lines (59 loc) · 1.69 KB
/
pyticker.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /usr/bin/python3
import os, urllib.request, time
import ansicolors
import sys
import tickeritem
import signal
import stockthread
import tickercleanup
from stockutils import formatFeed, updateList
def printFeed( tickerList, columns ):
newFeed = ''
count = 0
for item in tickerList:
newFeed = newFeed + item.getFormattedData() + ansicolors.AnsiColors.FG_WHITE + '|'
count = count + 1
if count > 10:
break
count = count - 1
tickerList[0].incrementOffset()
print( ansicolors.AnsiColors.BG_BLACK + newFeed[:columns + ( count * 2 )] );
#os.popen( 'echo -e "\r\033[K"', 'w' )
cleanList( tickerList )
def cleanList( tickerList ):
for item in tickerList:
if item.isFedThrough():
tickerList.remove( item )
def cleanUp( signal, frame ):
os.popen( 'clear', 'w' )
os.popen( 'tput cnorm', 'w' )
sys.exit( 0 )
def main():
os.popen( 'tput civis', 'w' )
tickerList = []
params = ''
if len( sys.argv ) > 1:
symbols = sys.argv.remove( sys.argv[0] )
for arg in sys.argv:
params = params + arg + '+'
params = params[:len( params ) - 1]
else:
params = 'GOOG+MSFT'
url = "http://download.finance.yahoo.com/d/quotes.csv?s=" + params + "&f=sl1d1t1c1ohgv&e=.csv"
f = urllib.request.urlopen( url )
feed = formatFeed( f )
updateList( tickerList, feed )
stockThread = stockthread.StockThread( tickerList, url )
cu = tickercleanup.CleanUp( stockThread )
signal.signal( signal.SIGINT, cu.clean_up )
stockThread.start()
os.popen( 'clear', 'w' )
count = 0
while True:
rows, columns = os.popen( 'stty size', 'r' ).read().split()
printFeed( tickerList, int( columns ) )
time.sleep( 0.2 );
os.popen( 'clear', 'w' )
count = count + 1
if __name__ == "__main__":
main()