-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstq.pl
executable file
·69 lines (64 loc) · 1.73 KB
/
stq.pl
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
#!/usr/bin/env python
import json
import pprint
import urllib2
import prettytable
import time
def get_stock_quote(ticker_symbol):
url = 'http://finance.google.com/finance/info?q=%s' % ticker_symbol
#lines = urllib2.urlopen(url).read().splitlines()
u = urllib2.urlopen(url)
content = u.read()
obj = json.loads(content[3:])
return obj
# return json.loads(''.join([x for x in lines if x not in ('// [', ']')]))
# u'c': u'+1.28',
# u'ccol': u'chg',
# u'cp': u'0.65',
# u'e': u'NYSE',
# u'id': u'18241',
# u'l': u'198.81',
# u'l_cur': u'198.81',
# u'lt': u'Mar 2, 4:03PM EST',
# u'ltt': u'4:03PM EST',
# u's': u'0',
# u't': u'IBM'}
if __name__ == '__main__':
filename = "stocksymbol"
FILE = open (filename, 'r')
tickarrp = []
tickarr = []
i = 0
for line in FILE:
tickarr.append(line.upper().rstrip("\n"))
i = i + 1 # why can't use ++i
if i%5 ==0:
i=0
tickerstr = ','.join(tickarr)
print tickerstr
tickarrp.append(tickerstr)
tickarr = []
if i!= 0:
tickerstr = ','.join(tickarr)
tickarrp.append(tickerstr)
print tickerstr
tickarr = []
while(1):
print "####################################################"
table = [["symbol" , "abs chg","%", "price", "time"]]
for tickerstr in tickarrp:
print tickerstr
quotes = get_stock_quote(tickerstr)
for obj in quotes:
data = []
data.append(obj['t'])
data.append(obj['c'])
data.append(obj['cp'])
data.append(obj['l_cur'])
data.append(obj['lt'])
table.append(data)
import sys
out = sys.stdout
prettytable.pprint_table(out, table)
time.sleep(10)
#pprint.pprint(quote)