forked from DhananjayPurohit/ISO-12-E1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
251 lines (205 loc) · 8.78 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
from flask import Flask, request, make_response, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS, cross_origin
from classifier import Classify
import readEmail
from extract import *
from werkzeug.utils import secure_filename
from recommendation import Trends, getCONTENT
import random
UPLOAD_FOLDER = '/uploadsflask'
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Database Config
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.sqlite3'
app.config['CORS_HEADERS'] = 'Content-Type'
db = SQLAlchemy(app)
CORS(app, resources={r"/*": {"origins": "*"}})
###### MODELS ######
class Teacher(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(90), nullable=False)
feedbacks = db.relationship('Feedback', backref='teacher',
cascade="all, delete-orphan", lazy='dynamic')
def __repr__(self):
return "<Teacher %r>"% self.id
class Feedback(db.Model):
id = db.Column(db.Integer, primary_key=True)
ques_1 = db.Column(db.Integer, nullable=False)
ques_2 = db.Column(db.Integer, nullable=False)
ques_3 = db.Column(db.Integer, nullable=False)
ques_4 = db.Column(db.Integer, nullable=False)
opinion = db.Column(db.Text, nullable=True)
teacher_id = db.Column(db.Integer, db.ForeignKey('teacher.id'))
def __repr__(self):
return "<Feedback %r>"% self.id
class Content(db.Model):
_tablename_ = 'content'
id = db.Column(db.Integer, primary_key=True)
subject = db.Column(db.String(150), nullable=False)
topic = db.Column(db.String(500), nullable=False)
video_content = db.Column(db.Boolean)
content = db.Column(db.Text)
votes = db.Column(db.Integer, default=0)
class Subject_list(db.Model):
__tablename__ = 'subject_list'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
user = db.Column(db.String(200))
password = db.Column(db.String(200))
year = db.Column(db.Integer)
branch = db.Column(db.String(20))
class branch_subject(db.Model):
__tablename__ = 'branch_subject'
id = db.Column(db.Integer, primary_key=True)
year = db.Column(db.Integer)
branch = db.Column(db.String(20))
subject = db.Column(db.String(150), nullable=False)
syllabus = db.Column(db.LargeBinary)
##### API #####
@app.route('/add_syllabus', methods=['POST'])
def add_subject():
subject_ = request.form.get('subject')
year_ = request.form.get('year')
branch_ = request.form.get('branch')
f = request.files['syllabus']
f.save(secure_filename(f.filename))
item = branch_subject(subject=subject_,year=year_,
branch=branch_,syllabus=f.read())
db.session.add(item)
db.session.commit()
return make_response("Syllabus Added Successfully")
@app.route('/login', methods=['POST'])
def user_login():
username = request.json.get('username')
password = request.json.get('password')
Opass = Subject_list.query.filter_by(user=username).first()
Opass1 = Opass.password
if password == Opass1:
sub_list = branch_subject.query.filter_by(year=Opass.year).filter_by(branch=Opass.branch).all()
subjects = []
for i in sub_list:
subjects.append(i.subject)
resp_ = make_response(str(subjects))
resp_.set_cookie('subjects', str(subjects))
return resp_
else:
return make_response("Error, Login again")
@app.route('/register', methods=['POST'])
def user_signup():
name_ = request.form.get('name')
user_ = request.form.get('username')
password_ = request.form.get('password')
year_ = request.form.get('year')
branch_ = request.form.get('branch')
item = Subject_list(name=name_,user=user_,password=password_,year=year_,
branch=branch_)
db.session.add(item)
db.session.commit()
return make_response("User registered Successfully")
@app.route('/get_content', methods=['GET'])
def get_content():
sub = request.args.get('sub', type = str)
sub = sub.replace("%20", " ")
subject_resp = Content.query.filter_by(subject=sub).all()
resp_list = ""
for i in subject_resp:
resp_list+=str(i.__dict__)
return jsonify(resp_list)
##### API #####
@app.route('/add', methods=['GET'])
def add_topic():
list = Topic_extractor(Pdf_reader("ds.pdf").full_text).final_list
for i in list:
topics = i.split(",")
for topic_ in topics:
t = random.choice([True,False])
try:
tpic = Content(subject='Data Structure', topic=topic_, video_content=t, content=getCONTENT(t, [topic_]).summary)
db.session.add(tpic)
db.session.commit()
print("new entry")
except Exception as e:
print(e)
pass
return make_response("User registered Successfully")
@app.route('/notif', methods=['GET'])
def get_notif_email():
email = readEmail.read()
return jsonify(email)
@app.route('/post_feedback', methods=['POST', 'GET'])
def save_feedback():
if request.method == 'POST':
ques_1 = request.form.get('ques_1')
ques_2 = request.form.get('ques_2')
ques_3 = request.form.get('ques_3')
ques_4 = request.form.get('ques_4')
opinion = request.form.get('opinion')
teacher = request.form.get('teacher')
teacher_obj = Teacher.query.filter(Teacher.name == teacher).one()
positive_score = Classify(opinion).classify()
if positive_score > 0.75:
feedback_obj = Feedback(ques_1=ques_1, ques_2=ques_2, ques_3=ques_3,
ques_4=ques_4, opinion=opinion, teacher=teacher_obj)
db.session.add(feedback_obj)
db.session.commit()
return make_response("Feedback Posted Successfully!")
else:
return make_response("Invalid Feedback. Please check your language quality")
else:
query_1 = [Feedback.query.filter(Feedback.ques_1.in_([1])).count(),
Feedback.query.filter(Feedback.ques_1.in_([2])).count(),
Feedback.query.filter(Feedback.ques_1.in_([3])).count(),
Feedback.query.filter(Feedback.ques_1.in_([4])).count(),
Feedback.query.filter(Feedback.ques_1.in_([5])).count()]
query_2 = [Feedback.query.filter(Feedback.ques_2.in_([1])).count(),
Feedback.query.filter(Feedback.ques_2.in_([2])).count(),
Feedback.query.filter(Feedback.ques_2.in_([3])).count(),
Feedback.query.filter(Feedback.ques_2.in_([4])).count(),
Feedback.query.filter(Feedback.ques_2.in_([5])).count()]
query_3 = [Feedback.query.filter(Feedback.ques_3.in_([1])).count(),
Feedback.query.filter(Feedback.ques_3.in_([2])).count(),
Feedback.query.filter(Feedback.ques_3.in_([3])).count(),
Feedback.query.filter(Feedback.ques_3.in_([4])).count(),
Feedback.query.filter(Feedback.ques_3.in_([5])).count()]
query_4 = [Feedback.query.filter(Feedback.ques_4.in_([1])).count(),
Feedback.query.filter(Feedback.ques_4.in_([2])).count(),
Feedback.query.filter(Feedback.ques_4.in_([3])).count(),
Feedback.query.filter(Feedback.ques_4.in_([4])).count(),
Feedback.query.filter(Feedback.ques_4.in_([5])).count()]
opinion_1 = []
for i in Feedback.query.all():
opinion_1.append(i.opinion)
resp = {"query_1": query_1,
"query_2": query_2,
"query_3": query_3,
"ques_4": query_4,
"opinion": opinion_1}
return jsonify(resp)
@app.route('/get_json_data', methods=["POST"])
def get_json_data():
college_name = request
vision = request.form.get('vis')
address = request.form.get('loc')
contact = request.form.get('contact')
logo_image = request.form.get('logo', '')
group = request.form.get('group', '')
slider_image = request.form.get('caro', '')
web_details = website_details(college_name=college_name, group=group,
logo_image=logo_image, slider_image=slider_image, contact=contact,
address=address, vision=vision)
try:
db.session.add(web_details)
db.session.commit()
return make_response("Website data saved successfully!")
except:
return make_response("Unable to save website data")
# Creates the dynamic route for the new website
@app.route('/<college>', methods=['GET'])
def serve_website(college):
print(college)
data = website_details.query.filter_by(college_name=college).one()
return render_template("base.html", data=data)
if __name__ == '__main__':
db.create_all()
app.run(debug=True)