-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
202 lines (152 loc) · 5.43 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
from flask import Flask, render_template, request, redirect, session, url_for, flash
from pymongo import MongoClient
from waitress import serve
import serial
import time
from decimal import Decimal
app = Flask(__name__, static_url_path='/static')
app.config["MONGO_URI"] = "mongodb+srv://wrieddude:Pranav369@cluster0.xu62g1z.mongodb.net/?retryWrites=true&w=majority"
client = MongoClient("mongodb+srv://wrieddude:Pranav369@cluster0.xu62g1z.mongodb.net/?retryWrites=true&w=majority")
db = client.get_database('askan')
records = db.user
app.secret_key = 'askan_hydroponics'
@app.route("/")
def main():
return render_template("index.html")
@app.route("/login", methods=["POST"])
def login():
if request.method == "POST":
username = request.form.get("username")
password = request.form.get("password")
user = records.find_one({"username": username})
if user is not None:
if user['password'] == password:
session['username'] = username # Store username in the session
return redirect('/home')
else:
return render_template('login.html', info="Invalid Username or Password")
else:
return render_template('login.html', info="User Not Found")
@app.route("/login-home", methods=["POST"])
def login_home():
return render_template('home.html')
@app.route("/home")
def home():
return render_template('home.html')
@app.route("/signin-home", methods=["POST"])
def signin_home():
full_name = request.form.get("fullname")
username = request.form.get("username")
password = request.form.get("password")
cfn_password = request.form.get("confirmPassword")
area_of_working = request.form.get("areaOfWork")
country = request.form.get("country")
gender = request.form.get("gender")
qualification = request.form.get("qualification")
purpose = request.form.get("purpose")
phone = request.form.get("phone")
email = request.form.get("email")
new_user = {
"fullname": full_name,
"username" : username,
"password" : password,
"Area_of_Working" : area_of_working,
"country" : country,
"gender" : gender,
"qualification": qualification,
"purpose": purpose,
"phone" : phone,
"email" : email
}
if password == cfn_password :
records.insert_one(new_user)
return redirect('/log-in')
else:
return render_template('/signup.html',info="Yours Passwords Dont Match Please Check it once")
@app.route("/log-in")
def login_button():
return render_template('/login.html')
@app.route("/signup")
def signup():
return render_template('/signup.html')
@app.route("/about-us")
def about():
return render_template('/aboutus.html')
@app.route("/contact-us")
def contact():
return render_template('/contact_us.html')
@app.route("/profile")
def profile():
if 'username' in session:
username = session['username']
user = records.find_one({"username": username})
if user:
return render_template('/profile.html', user=user)
else:
flash("User not found")
return redirect('/')
else:
return redirect('/')
@app.route("/activity")
def activity():
return render_template('/activity.html')
@app.route("/crops-entry")
def crops_entry():
return render_template('/Crops_Entry.html')
@app.route("/Equipment-Management")
def equipment_management():
try :
ser = serial.Serial('COM7', 9600)
lowerThreshold = 310
upperThreshold = 510
# Function to print water level message
def print_water_level_message(level):
if level <= 0:
print("Water Level: need more water")
elif 0 < level <= 400:
print("Water Level: need water")
else:
print("Water Level: full")
while True:
line = ser.readline().decode().rstrip()
new_line = int(float(line[-1]))
if line:
waterLevel = int(new_line)
print_water_level_message(waterLevel)
else:
print("The sensors are not connected or reload the website")
time.sleep(1)
except :
print("Connect the sensor")
return render_template('/Equipment_Management.html' , waterLevel = waterLevel)
@app.route("/products")
def products():
return render_template('/products.html')
@app.route("/index")
def index():
return render_template('/index.html')
@app.route("/gallery")
def gallery():
return render_template('/gallery.html')
@app.route("/base-contact")
def base_contact():
return render_template('/base_contactus.html')
@app.route("/services")
def services():
return render_template('/services.html')
@app.route("/blogs")
def blogs():
return render_template('/blogs.html')
@app.route("/faq")
def faq():
return render_template('/faq.html')
@app.route("/adverting")
def adverting():
return render_template('/adverting.html')
@app.route("/logout")
def logout():
session.pop('username', None)
flash('You have been logged out', 'success')
return redirect('/')
if __name__ == "__main__":
app.run(host="0.0.0.0",debug=True, port=8080)