This repository has been archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
app.py
55 lines (49 loc) · 1.88 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
from flask import Flask, request,render_template, url_for, redirect, send_file, send_from_directory
import string
import json
from SearchGrades import SearchGrades
app = Flask(__name__)
numberRecords = 0
jsonFile = open("data/Grades/yearWiseGrades.json", "r")
data = json.load(jsonFile)
jsonFile.close()
courses = []
with open("data/courses.json","r") as f:
courses_having_data = json.load(f)
for key in data:
string = ""
try:
string = key + " : " + courses_having_data[key]["name"]
except:
string = key
courses.append(string)
Grades = {}
@app.route('/', methods = ['GET','POST'])
def home():
if request.method == "POST":
code = request.form.get('getCode')
code = code.upper()
code = "".join(code.split())
code = code[:7]
Courselink = ""
with open("data/data_file.json","r") as read_file:
data = json.load(read_file)
for key in data.keys():
if(key == code ):
Courselink = "https://wiki.metakgp.org" + data[key]
Grades = SearchGrades(code)
numberRecords = len(Grades)
if( Grades == 'NA'):
if len (code) == 7 and code[:2].isalpha() and code[-5:].isdigit() :
return render_template('kronos.html',courseCode = code, Grades = Grades, result = "no-data", courses = courses)
else:
return render_template('kronos.html',courseCode = code, Grades = Grades, result = "invalid-code", courses = courses)
else:
return render_template('kronos.html',courseCode = code, Grades = Grades, result = "show-grades",courses = courses, Cwikilink = Courselink)
else:
Grades = {}
return render_template('kronos.html',courseCode = '', Grades = Grades, result = "on-start",courses = courses)
if __name__=="__main__" :
app.run()
else:
print(__name__)