-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
29 lines (23 loc) · 791 Bytes
/
main.py
File metadata and controls
29 lines (23 loc) · 791 Bytes
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
from flask import Flask
import json
f = open("backend-course-data.json")
data = json.load(f)
app = Flask(__name__)
@app.route('/<string:searchString>/')
def hello(searchString):
searchStrings = searchString.split(" ")
results = []
for course in data:
if searchString == course["course_code"]:
return course
relevancy = 0
for str in searchStrings:
if course["title"]:
relevancy += 5 * course["title"].lower().count(str.lower())
if course["description"]:
relevancy += course["description"].lower().count(str.lower())
if relevancy > 0:
results.append([course, relevancy])
results = sorted(results, key=lambda x:x[1], reverse=True)
return results
app.run()