diff --git a/Backend/__pycache__/app.cpython-39.pyc b/Backend/__pycache__/app.cpython-39.pyc index c723a9a..f56557e 100644 Binary files a/Backend/__pycache__/app.cpython-39.pyc and b/Backend/__pycache__/app.cpython-39.pyc differ diff --git a/Backend/addresult.py b/Backend/addresult.py new file mode 100644 index 0000000..21fc35b --- /dev/null +++ b/Backend/addresult.py @@ -0,0 +1,35 @@ +import requests +import json + + +def result(): + try: + wa = " http://127.0.0.1:5000/addresult" + facultyid = int(input("Enter faculty id: ")) + type = input("Enter the type: ") + type = type.lower() + studentid = int(input("Enter student id/ roll no: ")) + physicsmarks = int(input("Enter physics marks: ")) + chemmarks = int(input("Enter chemistry marks: ")) + mathsmarks = int(input("Enter maths marks: ")) + englishmarks = int(input("Enter english marks: ")) + data = { + "facultyid": facultyid, + "type": type, + "studentid": studentid, + "physicsmarks": physicsmarks, + "chemmarks": chemmarks, + "mathsmarks": mathsmarks, + "englishmarks": englishmarks, + } + res = requests.post(wa, json=json.dumps(data)) + print(res) + data = res.json() + ans = data["msg"] + print(ans) + + except Exception as e: + print(e) + + +result() diff --git a/Backend/api.py b/Backend/api.py index a72deb4..da4a318 100644 --- a/Backend/api.py +++ b/Backend/api.py @@ -1,18 +1,17 @@ import requests import json - try: - wa = " http://192.168.1.102:5000/check" - id = int(input('Enter roll no: ')) - password = input('Enter password: ') - - data = {'id':id, "password":password} - res = requests.post(wa,json=json.dumps(data)) - print(res) + wa = " http://127.0.0.1:5000/check" + id = int(input("Enter roll no: ")) + password = input("Enter password: ") + + data = {"id": id, "password": password} + res = requests.post(wa, json=json.dumps(data)) + print(res) - data = res.json() - ans =data['msg'] - print(ans) + data = res.json() + ans = data["msg"] + print(ans) except Exception as e: - print(e) \ No newline at end of file + print(e) diff --git a/Backend/app.py b/Backend/app.py index 793f48b..538d52f 100644 --- a/Backend/app.py +++ b/Backend/app.py @@ -1,31 +1,30 @@ from flask import Flask, request, jsonify from flask_sqlalchemy import SQLAlchemy -from flask_cors import CORS, cross_origin -from sqlite3 import * +from flask_cors import CORS +from sqlite3 import connect import json app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///student_results.db" +app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///student_results.db" db = SQLAlchemy(app) +CORS(app) + +# schema definition -#schema definition class StudentLoginModel(db.Model): id = db.Column(db.Integer, primary_key=True) password = db.Column(db.String(10)) student = db.Column(db.String(10)) faculty = db.Column(db.String(10)) - - def __init__(self,id,password,student,faculty): + def __init__(self, id, password, student, faculty): self.id = id self.password = password self.student = student self.faculty = faculty - - class StoreModel(db.Model): rno = db.Column(db.Integer, primary_key=True) @@ -34,43 +33,73 @@ class StoreModel(db.Model): maths = db.Column(db.Integer) eng = db.Column(db.Integer) - def __init__(self,phy,chem,maths,eng): + def __init__(self, rno, phy, chem, maths, eng): + self.rno = rno self.phy = phy self.chem = chem self.maths = maths self.eng = eng - - -@app.route('/') +@app.route("/") def index(): return "Hello From Flask Here" -@app.route('/check', methods=['POST','GET']) + +@app.route("/check", methods=["POST", "GET"]) def check(): - + data = json.loads(request.get_json()) - id = data['id'] - password = data['password'] + id = data["id"] + password = data["password"] con = None try: - con = connect('student_results.db') + con = connect("student_results.db") cursor = con.cursor() - cursor.execute("insert into StudentLoginModel (id, password) values ('%d','%s')" % (id,password)) + cursor.execute( + "insert into StudentLoginModel (id, password) values ('%d','%s')" + % (id, password) + ) con.commit() - return jsonify({'msg': "Details are successfully stored in the database..!"}) + return jsonify({"msg": "Details are successfully stored in the database..!"}) + + except Exception as e: + con.rollback() + return jsonify({"msg": "There's some issue: " + str(e)}) + finally: + if con is not None: + con.close() + + +@app.route("/addresult", methods=["POST", "GET"]) +def addresult(): + data = json.loads(request.get_json()) + facultyid = data["facultyid"] + type = data["type"] + studentid = data["studentid"] + physicsmarks = data["physicsmarks"] + chemmarks = data["chemmarks"] + mathsmarks = data["mathsmarks"] + englishmarks = data["englishmarks"] + con = None + try: + con = connect("student_results.db") + cursor = con.cursor() + if type != "faculty" and facultyid > 0: + return jsonify({"msg": "Access Denied"}) + cursor.execute( + "Insert into StoreModel (rno, phy, chem, maths, eng) values ('%d','%d','%d','%d','%d')" % (studentid, physicsmarks, chemmarks, mathsmarks, englishmarks) + ) + con.commit() + return jsonify({"msg": "Details are successfully stored in the database..!"}) except Exception as e: con.rollback() - return jsonify({'msg': "There's some issue: " + str(e)}) - + return jsonify({"msg": "There's some issue: " + str(e)}) finally: - if con is not None: - con.close() + if con is not None: + con.close() - - -if __name__ == '__main__': - app.run(host="0.0.0.0", debug=True, port=5000) +if __name__ == "__main__": + app.run(debug=True, port=5000) diff --git a/student_results.db b/student_results.db index b3a8902..88df1cd 100644 Binary files a/student_results.db and b/student_results.db differ