forked from Kaushik-Iyer/carbonscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
53 lines (43 loc) · 1.62 KB
/
app.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
53
from flask import Flask,render_template,redirect,request,url_for
from urllib.request import urlopen
import json
app=Flask(__name__)
@app.route('/form',methods=['GET','POST'])
def form():
if request.method=='POST':
distance=request.form.get('distanceInput')
fuel=request.form.get("fuelConsumed")
type=request.form.get('fuelInput')
print(type,distance,fuel)
if type=='petrol':
emissions= (float(fuel)*2640)/(float(distance))
emissions=float("{:.2f}".format(emissions))
elif type=='diesel':
emissions=(float(fuel)*2392)/float(distance)
emissions=float("{:.2f}".format(emissions))
comparison=122.3
if comparison<emissions:
keyword='more'
percentage=(((emissions-comparison)/emissions) * 100)
elif comparison>emissions:
keyword='less'
percentage=abs((((emissions-comparison)/emissions) * 100))
percentage=float("{:.2f}".format(percentage))
try:
return render_template('output.html',emissions=emissions,distance=distance,keyword=keyword,percentage=percentage)
except:
return 'Cannot take in values'
return render_template('form.html')
# @app.route('/result',methods=['POST','GET'])
# def result():
# if request.method=='POST':
# result=request.form
# return render_template('result.html',result=result)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/output')
def output():
return render_template('output.html')
if __name__=='__main__':
app.run(debug=False)