-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstock.py
52 lines (38 loc) · 1.82 KB
/
stock.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
46
47
48
49
50
51
52
from flask import Flask
from flask import request
from flask import render_template
from bs4 import BeautifulSoup
import requests
import json
from urllib.request import urlopen
app = Flask(__name__)
@app.route('/')
def GetStock():
return render_template("GetStock.html")
@app.route('/', methods=['POST'])
def my_form_post():
text = request.form['text']
stock_name = text.upper()
url="https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol="+stock_name+"&illiquid=0&smeFlag=0&itpFlag=0"
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text,"html.parser")
p = soup.find('div',{'id':'responseDiv'})
data = json.loads(p.string)
info = data['data']
if not info:
return render_template("error.html")
else:
info1 = info[0]
Last_price = info1["lastPrice"]
PreviousDay_Closing_price = info1["previousClose"]
Opening_price = info1["open"]
Highest_of_day = info1["dayHigh"]
Lowest_of_day = info1["dayLow"]
Closing_price = info1["closePrice"]
Percentage_change = info1["pChange"]
stock_details={"Last price ":Last_price, "PreviousDay Closing price":PreviousDay_Closing_price , "Opening price":Opening_price , "Highest of day":Highest_of_day
, "Lowest of day ":Lowest_of_day, "Closing price":Closing_price , "Percentage change":Percentage_change}
return render_template ("StockInfo.html",details=stock_details)
if __name__ == '__main__':
app.run(debug=True)