-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstock_check2.py
More file actions
57 lines (36 loc) · 1.66 KB
/
stock_check2.py
File metadata and controls
57 lines (36 loc) · 1.66 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask, render_template, redirect, url_for, request
import requests
import json
import requests
url = "https://financialtimesmikilior1v1.p.rapidapi.com/getAspectsList"
payload = ""
headers = {
'x-rapidapi-host': "FinancialTimesmikilior1V1.p.rapidapi.com",
'x-rapidapi-key': "9ef0f41046msh0337a9f0ca5734dp12a2d8jsnbd16d28c80e5",
'content-type': "application/x-www-form-urlencoded"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
app = Flask(__name__)
@app.route('/stock', methods=['GET'])
def stock():
return render_template('stock.html')
@app.route('/result', methods=['GET', 'POST'])
def result():
error = None
if request.method == 'POST':
tickerCode = request.form['stockSymbol']
api_key = request.form['APIKey']
url = "https://www.alphavantage.co/query"
querystring = {"function": "TIME_SERIES_INTRADAY","symbol": tickerCode, "interval": "5min", "apikey": api_key}
headers = {
'cache-Control': "no-cache",
'postman-Token': "c50d8ad2-56d2-4114-9244-6dc770d9e5c0,b7b7eaec-bdc1-453f-bd6b-96fa8ce1e741",
}
response = requests.request("GET", url, headers=headers, params=querystring)
stockData = json.loads(response.text)
lastRefreshedDate = stockData["Meta Data"]["3. Last Refreshed"]
latestStockPrices = stockData["Time Series (5min)"][lastRefreshedDate]
closingPrice = latestStockPrices["4. close"]
volume = latestStockPrices["5. volume"]
return render_template('stock_price.html', tCode=tickerCode, sPrice=closingPrice, cVolume=volume, dTime=lastRefreshedDate)