From 88955fe7e9c346b2c1afbdfe379b82a2eb956493 Mon Sep 17 00:00:00 2001 From: sohil Date: Tue, 4 Jan 2022 17:46:08 +0530 Subject: [PATCH] Added api to add result of student Created api to add result of student by faculty --- Backend/__pycache__/app.cpython-39.pyc | Bin 548 -> 2395 bytes Backend/addresult.py | 35 +++++++++++ Backend/api.py | 23 ++++--- Backend/app.py | 83 +++++++++++++++++-------- student_results.db | Bin 20480 -> 20480 bytes 5 files changed, 102 insertions(+), 39 deletions(-) create mode 100644 Backend/addresult.py diff --git a/Backend/__pycache__/app.cpython-39.pyc b/Backend/__pycache__/app.cpython-39.pyc index c723a9a79a0536d39fe4347a8865213d918bee38..f56557ec34b9d99a42367c9f629c2d90a22ee7a7 100644 GIT binary patch literal 2395 zcmbVNOK%)S5bmD$KD@EluQ&uW2qI@iWLqF{up)?KI}emNkaZNLWoa~?Zm-9l$EJHW zcvowLrAJp(;_1_nOVqsWW_eK3)zUAxWr0@ zY(`~P7F1OBD64WyRJVq>eVqtXR6$b{Hhw9&O}N8L&j~My+SY|VoehJg%qyU&9BD>G zb-&K52b2%-+H(S{M`5=*zrct2NK51O7aAYsW5vjrsPOS^P5uNk#`y%FNg{%5 zrFU69jlxXK&(6-Otiwf;c~YoOl&KlM&L(m7y~R7r_n&x63#$t^7n;l7qlb3`{PF3> zgw73UY85~bMmb@c(6M}r|_K8RO8X)cKfLh-G z)H!LAmvp6JS5z^06xpvbJwgpV~+wGZl zH+MWQOv23bCSXV901#>wZ|~AMN6Z{gUTIWuW#Y%e^YXIi#VPMZC|5o2X~&O_Ml`;j zTZ?JbiId#En`ELTWN{*9H8U9|turT+qwxRYaHpV-I<#yUnnK?@ba?P;h5j5(-o)a6 z(`3s8ir5266!H;W3i*gCgLzcj(|4#^6f#pC6y}jAZ4Gf~( zjQwm=<+?~(4O8O5$}wC#j(~SBClM|p zOaU-mCh0%^^Ixy%5-da06jBzis5*Exi6gJ+?74fQpf5rOFN{<0tG3b`zaye3b#KWu zc8i4L-VsuqI_lep&do64V&@~+L173IO}cBrA7+q+}N=LvJ4R zl{c&GtlBsC=p-4ew#XBxBfI7|=9_(fIN4_~GDqf4{_^|rXi`7=?{CMNIoJt2?yQ`o zm|p#Sa_)T|CXiz?H%zkBJ(m*Pt0BMU9_O)!`^=A^Hn>-(ukh(>(^u4VBiCcq>V3Q< zGCz!z>r3IPP7nyCHabz%brr@Dhwa^LQ@GsE{B>W6nVI){W2>8R^V7;zX)N4Osg9U; z8$-E)btgBY)aOd-aAC}8iOfT-gwjlME9gj-N{H(n5p*)atRRi!Fq6o$+zg^riM+JD z6Nq*erU`Ro8b#}n7;{}^5`x=6Gfw=%bSPx<3NEInnTSCL+ab^9KvbUs5WPkncnx?5 zUyWLa+M!`Mv}S|mPff!at`72FHNf(rLnZPTQ)=voiRZ0`-$9r)wA|!kz0+bwJC#{u zf|(mwfhF?1ICya&He6^uD6#&a1WT+(tUOQ$sZ9FXf!3(!T$ zM%XIS05glcRwUOVc$q0v@M95K15fjN5VhlY<4v=u65_s`&|V5>R3X}B%Ysl5-ExT{LWqYptR07OBDKB3feZfu zj{GG{oH%jd5A=k+duYd+r#B<}&4;VWBqiQ{Klu0lJ|*N&2yPqq!Bg+{od-!IRYcRA z(!e7XX_m7MXDZe_=X#WnC;=?1R%=Z}lG7SI+4hszf)7mL&48Q67i zx?*ur=@YPn>YqakSoH>r!>V3GD~qb@_PR^Qn^wYw2*o20B*L*rC(2S+Oh(^`kNupBvjdF5$y)=Hkv^e>}@_{xK{7gGRo);idhos_iC_g><@2*9I+yK{5PP ysMJ;(%F;34lH+KG9=1&|9NL>fw=8t(#J)CiQ1B!y&ff8m(Twgg5eb?yLH`3U3WR6? 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 b3a8902056e9c2b62ee2cd5568a79f0ef1f7fad7..88df1cd8d931c64592d8832099dd7ec70823052f 100644 GIT binary patch delta 160 zcmZozz}T>Wae_1>$3z)tRt^R||Jscy3;20h_)jqKf8~G9f1UrtWjG81V&MP7|Be3x|EtY{3b*(tf6!-PN@f94A{>L>p#l^tDz{LNRf&VxE*Uf?kFTsYer!cWFGjb*a0QmAP AF#rGn delta 89 zcmZozz}T>Wae_1>>qHr6R#pZ*i4z-B7VvX1^IvD+|H}WI|N3S@g_Hb~ugmKK#Xd0b k|Kb0}|6#MB!z2F5AM{0-7zBXqC;Ss9h_P`o00Eo}01D9@X#fBK