-
Notifications
You must be signed in to change notification settings - Fork 20
/
api.py
61 lines (45 loc) · 2 KB
/
api.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
56
57
58
59
60
61
# This file will outline the routes that can be called / accessed with the API
# Written in python using flask to perform API calls
import importlib
from flask import Flask, jsonify
# Grab the course data from the data.py processing script
from data import parse_courses, number_of_courses, number_of_pages
# moduleName = input('utils')
# importlib.import_module(utils)
app = Flask(__name__)
@app.route('/2021/courses_by_gpa/<page_number>')
def courses_by_gpa(page_number):
try:
course_list = parse_courses(page_number, '', '', '', 'GPA').to_json(orient='records')
return course_list
except AttributeError: # should probably find a better way to do this, could hide actual AttributeErrors
return 'Bad request!', 400
@app.route('/2021/courses_by_name/<page_number>')
def courses_by_name(page_number):
try:
course_list = parse_courses(page_number, '', '', '', 'Course Name').to_json(orient='records')
return course_list
except AttributeError:
return 'Bad request!', 400
@app.route('/2021/courses_by_size/<page_number>')
def courses_by_size(page_number):
try:
course_list = parse_courses(page_number, '', '', '', 'size').to_json(orient='records')
return course_list
except AttributeError:
return 'Bad request!', 400
@app.route('/2021/number_of_courses')
def json_number_of_courses():
return jsonify(number_of_courses())
@app.route('/2021/number_of_pages')
def json_number_of_pages():
return jsonify(number_of_pages())
#TODO:
# Create a route that will display information about a specific course when you get it
# Create a route that will display specific information about courses in a department
# Create a route that will filter courses based on total size
# Create a route that will retrieve courses taught by a specific instructor
# Create a route that will display all the geneds
# Create a route that will display a gened of a specific category
# Create a route that will filter by department + gpa
# Sort all the different routes into seperate files