-
Notifications
You must be signed in to change notification settings - Fork 6
/
stocks.py
45 lines (33 loc) · 1.78 KB
/
stocks.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
from flask import Flask, render_template, request
from iexfinance.stocks import Stock
from urllib.request import urlopen
import json
import re
#class Stock:
# def __init__(self,name):
# self.price =
# self.name = name
Tesla = Stock("TSLA")
Apple = Stock("AAPL")
Google = Stock("GOOGL")
Microsoft = Stock("MSFT")
Amazon = Stock("AMZN")
#print(Stock1.name)
def getChart(name):
json1 = urlopen("https://api.iextrading.com/1.0/stock/"+ name + "/chart/1y").read()
j = json.loads(json1)
answer = {}
for dict in j:
answer[dict['date']] = dict['open']
return answer
# s = "{"
# for d in j:
# s+= d['date'] + ":" + d['open']
# s += "}"
# return s
def getQuote(name):
name = re.sub(r'[-]', '.', name)
print(name)
json1 = urlopen("https://api.iextrading.com/1.0/stock/"+ name + "/quote").read()
j = json.loads(json1)
return j