-
Notifications
You must be signed in to change notification settings - Fork 0
/
api04.py
28 lines (22 loc) · 866 Bytes
/
api04.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
from flask import Flask
import requests
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hello WorLd!"
@app.route('/company')
def get_company_data():
user_agent = {'User-agent': 'Mozilla/5.0'}
symbol = "DIS" # Ticker de Disney
url = f"https://query2.finance.yahoo.com/v10/finance/quoteSummary/{symbol}?modules=price%2CsummaryDetail%2CpageViews%2CfinancialsTemplate"
r = requests.get(url, headers=user_agent)
print(r.json())
my_data_selection = {
"nombre": r.json()["quoteSummary"]["result" ][0]["price"]["shortName"],
"ticker": r.json()["quoteSummary"]["result"][0]["price"]["symbol"],
"precio": r.json()["quoteSummary"]["result"][0]["summaryDetail"]["previousClose"]["raw"]
}
print(my_data_selection)
return my_data_selection
if __name__ == '__main__':
app.run()