-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
94 lines (69 loc) · 2.46 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
from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
import os
from datetime import datetime
app = Flask(__name__)
project_dir = os.path.dirname(os.path.abspath(__file__))
database_file = 'sqlite:///machine.db'
app.config['SQLALCHEMY_DATABASE_URI'] = database_file
db = SQLAlchemy(app)
class Book(db.Model):
id = db.Column(db.Integer, primary_key = True)
rollnumber = db.Column(db.Integer, nullable = False)
room = db.Column(db.Integer, nullable = False)
machine = db.Column(db.Integer, nullable = False)
time = db.Column(db.DateTime,default = datetime.utcnow)
db.create_all()
@app.route('/',methods=["POST","GET"])
def root():
machi = [0,0,0]
now = datetime.utcnow()
machs = Book.query.order_by(Book.id).all()
for mach in machs:
if mach.machine == 1:
machi[0] = mach
if mach.machine == 2:
machi[1] = mach
if mach.machine == 3:
machi[2] = mach
if request.form:
form = request.form
b = Book(
rollnumber = form['roll'],
room = form['room'],
machine = form['num']
)
if (now - machi[int(form['num']) - 1].time).seconds/60 < 50:
# if (now - machi[int(form['num']) - 1].time).seconds < 2400:
return redirect (url_for('error'))
db.session.add(b)
db.session.commit()
return redirect('/')
else:
mach1=0
mach2=0
mach3=0
machs = Book.query.order_by(Book.id).all()
for mach in machs:
if mach.machine == 1:
machi[0] = mach
if mach.machine == 2:
machi[1] = mach
if mach.machine == 3:
machi[2] = mach
return render_template('index.html',mach1=machi[0],mach2=machi[1],mach3=machi[2],now=now)
@app.route("/error",methods=["GET"])
def error():
machi = [0,0,0]
now = datetime.utcnow()
machs = Book.query.order_by(Book.id).all()
for mach in machs:
if mach.machine == 1:
machi[0] = mach
if mach.machine == 2:
machi[1] = mach
if mach.machine == 3:
machi[2] = mach
return render_template("error.html",mach1=machi[0],mach2=machi[1],mach3=machi[2],now=now)
if __name__ == '__main__':
app.run(debug = True)