Advertisement
Guest User

stock2.py

a guest
Nov 30th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. import urllib2
  4. import json
  5. import time
  6. import sys
  7.  
  8. class GoogleFinanceAPI:
  9. def __init__(self):
  10. self.prefix = "http://finance.google.com/finance/info?client=ig&q="
  11.  
  12. def get(self,symbol,exchange):
  13. url = self.prefix+"%s:%s"%(exchange,symbol)
  14. u = urllib2.urlopen(url)
  15. content = u.read()
  16.  
  17. obj = json.loads(content[3:])
  18. return obj[0]
  19.  
  20.  
  21. if __name__ == "__main__":
  22. c = GoogleFinanceAPI()
  23. quote = c.get(sys.argv[1],sys.argv[2])
  24. words = str(quote).split()
  25. farve = "${color3}"
  26. change = str(words[1][2:-5])
  27. if change[0] == "-":
  28. farve = "${color5}"
  29. if change == "0.00":
  30. farve = "${color1}"
  31. if words[14][2:-2] == "el_fix":
  32. change = str(words[41][2:-2])
  33. print words[1][2:-2] + " ${goto 210}" + str(farve) + change + "${color1}"
  34. else:
  35. print words[14][2:11] + " ${goto 210}" + str(farve) + change + "${color1}"
  36.  
  37. #print words
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement