Advertisement
ylSiew

Untitled

Aug 31st, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. import urllib2
  2. import json
  3. import time
  4.  
  5. # Form: http://digitalpbk.com/stock/google-finance-get-stock-quote-realtime
  6. class GoogleFinanceAPI:
  7.     def __init__(self):
  8.         self.prefix = "http://finance.google.com/finance/info?client=ig&q="
  9.    
  10.     def get(self,symbol,exchange):
  11.         url = self.prefix+"%s:%s"%(exchange,symbol)
  12.         u = urllib2.urlopen(url)
  13.         content = u.read()
  14.        
  15.         obj = json.loads(content[3:])
  16.         return obj[0]
  17.        
  18.        
  19. if __name__ == "__main__":
  20.     c = GoogleFinanceAPI()
  21.    
  22.     while 1:
  23.         quote = c.get("MSFT","NASDAQ")
  24.         print quote
  25.         time.sleep(30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement