Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Stock Market Data
- from urllib import request
- import turtle
- turtle.setup(550,360)
- turtle.screensize(550,360)
- turtle.setworldcoordinates(-40,-25,510,335)
- turtle.hideturtle()
- def turtlegraph(x,y, x1, x2, y1, y2, title):
- turtle.setpos(0,0)
- turtle.clear()
- turtle.tracer(0)
- turtle.seth(0)
- turtle.pendown()
- turtle.seth(0)
- turtle.fd(500)
- turtle.bk(500)
- turtle.seth(90)
- turtle.fd(300)
- turtle.bk(300)
- maxnum = max(y)
- maxin = max(x)
- minnum = min(y)
- minin = min(x)
- turtle.penup()
- turtle.setpos(-10,290)
- turtle.write(y2, False, align="right")
- turtle.setpos(-10,-10)
- turtle.write(y1, False, align="right")
- turtle.setpos(500,-20)
- turtle.write(x2, False, align="right")
- turtle.setpos(0,-20)
- turtle.write(x1, False, align="left")
- turtle.setpos(0,320)
- turtle.write(title, False, align="left")
- turtle.update()
- # Now sort points
- count = 0
- points = []
- for valx in x:
- points.append([valx,y[count]])
- count += 1
- points.sort()
- # Now add points
- turtle.setpos(0,0)
- for point in points:
- newx = (point[0]-minin)*500/(maxin-minin)
- newy = (point[1]-minnum)*300/(maxnum-minnum)
- turtle.setpos(newx,newy)
- turtle.pendown()
- turtle.update()
- def dosymbol(s):
- s = s.upper()
- a = str(int(input("Start Month: "))-1)
- b = str(int(input("Start Day: ")))
- c = str(int(input("Start Year: ")))
- d = str(int(input("End Month: "))-1)
- e = str(int(input("End Day: ")))
- f = str(int(input("End Year: ")))
- info = request.urlopen("http://ichart.finance.yahoo.com/table.csv?s="+s+"&a="+a+"&b="+b+"&c="+c+"&d="+d+"&e="+e+"&f="+f)
- info.readline()
- x = []
- y = []
- count = 1
- monthvals = [0,31,59,90,120,151,181,212,243,273,304,334]
- for line in info:
- line = line.decode()
- vals = line.split(',')
- dats = vals[0].split('-')
- date = float(dats[0])*365.25+monthvals[int(dats[1])-1]+float(dats[2])
- close = vals[4]
- x.append(float(date))
- y.append(float(close))
- if(count==1):
- x2=vals[0]
- count += 1
- x1 = vals[0]
- y2 = max(y)
- y1 = min(y)
- turtlegraph(x,y,x1,x2,y1,y2,s)
- ticker = input("Ticker Symbol: ")
- while(ticker!=''):
- dosymbol(ticker)
- ticker = input("Ticker Symbol: ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement