-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseacourses.py
More file actions
105 lines (88 loc) · 3.24 KB
/
seacourses.py
File metadata and controls
105 lines (88 loc) · 3.24 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
SeaCourses
~~~~~~~~~~~~~~
An alternate course search and planning app for Stony Brook University
:author: Brian Chen, Kevin Li, Brian Yang
"""
from flask import Flask, render_template, jsonify, Response, request
from pymongo import MongoClient
import json
from classes.course import Course
import pymysql
app = Flask(__name__)
@app.route('/search/', defaults={'page': 0})
@app.route('/search/<int:page>')
def connect(page):
# pull out search variables
dept_code = request.args.get('deptCodeNum')
prof = request.args.get('prof')
dec = request.args.get('dec')
days = request.args.get('days')
client = MongoClient("mongodb://localhost:27017")
cursor = client.seacourses.s16courses.find({
'deptCodeNum': {'$regex': '^' + request.args.get('deptCodeNum', '')},
'prof': {'$regex': '^' + request.args.get('prof', '')},
'dec': {'$regex': '^' + request.args.get('dec', '')},
'days': {'$regex': '^' + request.args.get('days', '')},
}).sort([('deptCodeNum', 1)])
# conn = pymysql.connect(host='localhost',
# user='root',
# password='',
# db='seacourses',
# charset='utf8mb4',
# cursorclass=pymysql.cursors.DictCursor)
# try:
# with conn.cursor() as cursor:
# query = "SELECT * FROM s16courses"
# finally:
# conn.close()
courses = []
for course in cursor:
courses.append(Course(course))
def serialize(obj):
return obj.__dict__
return Response(response=json.dumps(courses, default=serialize),
status=200,
mimetype="application/json")
# This is just to make sure the mongo table is correct. which it isn't. for now. :'(
@app.route('/test')
def test():
# client = MongoClient("mongodb://localhost:27017")
# cursor = client.seacourses.courseInfo.find()
# html = "<table>"
# html += "<tr><td>Dept Code</td><td>Name</td><td>ID</td>"
#
# for document in cursor:
# if len(document["name"]) < 1:
# html += "<tr>"
# html += "<td>" + document["deptCodeNum"] + "</td>"
# html += "<td>" + document["name"] + "</td>"
# html += "<td>" + document["_id"] + "</td>"
# html += "</tr>"
# html += "</table"
# return html
client = MongoClient("mongodb://localhost:27017")
return render_template('index.html',
courses=client.seacourses.courseInfo.find())
@app.route('/schedule')
def schedule():
return render_template('schedule.html')
@app.route('/')
def main():
return render_template('main.html')
# @app.route('/ratemyprof')
# def scrape():
# url = 'http://www.ratemyprofessors.com/search.jsp?query=mary+diaz+stony+brook'
# with urllib.request.urlopen(url) as f:
# soup = BeautifulSoup(f.read())
# test = soup.find_all('li')
# html = len(test)
# # for item in test:
# # html += test
# return html
# # return render_template('scrape.html')
@app.route('/builder')
def build():
return render_template('builder.html')
if __name__ == '__main__':
app.run(debug=True)