Skip to content

Commit

Permalink
Merge pull request #30 from sohilkhanduja/changes
Browse files Browse the repository at this point in the history
Added API to add result of student
  • Loading branch information
Ash515 committed Jan 4, 2022
2 parents 1bdd8c2 + 88955fe commit f7648ce
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 39 deletions.
Binary file modified Backend/__pycache__/app.cpython-39.pyc
Binary file not shown.
35 changes: 35 additions & 0 deletions Backend/addresult.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import requests
import json


def result():
try:
wa = " https://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()
23 changes: 11 additions & 12 deletions Backend/api.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import requests
import json

try:
wa = " https://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 = " https://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)
print(e)
83 changes: 56 additions & 27 deletions Backend/app.py
Original file line number Diff line number Diff line change
@@ -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:https:///student_results.db"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:https:///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)
Expand All @@ -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)
Binary file modified student_results.db
Binary file not shown.

0 comments on commit f7648ce

Please sign in to comment.