-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
174 lines (143 loc) · 4.64 KB
/
server.js
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const express = require("express");
const scraper = require("./scraper.js");
const path = require("path");
const app = express();
app.set("port", (process.env.PORT || 5000));
const errorHandler = function(error, httpResponse) {
console.log(error.stack);
console.log("Error: " + error);
httpResponse.sendStatus(500);
}
/* ENDPOINT: GET /schoolCalendar
--------------------------
A scraper for the general school calendar.
Responds with the parsed calendar data as a JSON array of calendar event objects
sorted from earliest to latest. Fetches the next two months of calendar data.
Each object has the format:
{
"eventName": "US Leadership Workshop",
"startDateTime": "2016-11-28T14:45:00.000Z",
"endDateTime": "2016-11-28T16:05:00.000Z",
"location": "Theatre,Theatre Lobby"
}
Each event is guaranteed to have the following fields:
- startDateTime: start date/time string of event (JS date string)
- eventName: name of the event
Additionally, an event may have the following fields:
- endDateTime: end date/time string of event (JS date string)
- location: the name of the event's location
Assumes events span at most one full day. Events with no explicit start TIME
(hours, minutes) have a specified start time of midnight.
--------------------------
*/
app.get("/schoolCalendar", function(req, res) {
"use strict";
scraper.scrapeSchoolCalendars(new Date()).then(function(calendarData) {
res.json(calendarData);
}, function(error) {
errorHandler(error, res);
});
});
/* ENDPOINT: GET /athleticsCalendar
--------------------------
A scraper for the athletics calendar, including practices and games.
Responds with an object with the following format:
{
"games": [
...
],
"practices": [
...
]
}
Each array contains athletics event objects in chronological order for athletics
games and practices scraped from the school website. The information scraped
for games and practices is slightly different, however. The games events have
the following format:
{
"month": "Sep",
"date": 28,
"year": 2016,
"team": "Boys' Varsity Soccer",
"opponent": "Other School"
"time": "2016-11-28T15:45:00-05:00",
"location": "Back Field",
"isHome": true,
"result": null,
"status": "CANCELLED"
}
Every game event object is guaranteed to have the following fields:
- month: an abbreviated name for the event month
- date: the numeric date
- year: the numeric year
- team: the school team competing
- isHome: boolean whether or not this is a home game
Additionally, a game event object may have the following fields:
- opponent: the opposing team name
- time: a datetime string
- location: the name of the game's location (NOT necessarily address)
- result: "Win" or "Loss" or another string indicator of game result
- status: "CANCELLED" or another string indicator of game status
The practices events have the following format (a subset of the game object):
{
"month": "Sep",
"date": 28,
"year": 2016,
"team": "Boys' Varsity Soccer",
"time": "2016-11-28T15:45:00-05:00",
"location": "Back Field",
"status": "CANCELLED"
}
All fields in a practice object are the same as their corresponding fields in a
game object.
--------------------------
*/
app.get("/athleticsCalendar", function(req, res) {
"use strict";
scraper.scrapeAthleticsCalendars().then(function(calendarData) {
res.json(calendarData);
}, function(error) {
errorHandler(error, res);
});
});
/* ENDPOINT: GET /athleticsTeams
-----------------------------------------
A scraper for athletics teams information. Responds with a collection of three
arrays, one for each season, of athletics team names (as strings):
{
"Fall": [
"Cross Country",
"Girls' Varsity Tennis",
...
],
"Winter": [
...
],
"Spring": [
...
]
}
-----------------------------------------
*/
app.get("/athleticsTeams", function(req, res) {
"use strict";
scraper.scrapeAthleticsTeams().then(function(teams) {
res.json(teams);
}, function(error) {
errorHandler(error, res);
});
});
/* ENDPOINT:
----------------
A catch-all endpoint that sends back a link to the GitHub repo.
----------------
*/
app.get("*", function(req, res) {
res.send("<html><h1>Maret Calendar Scraper</h1>See " +
"<a href='https://github.com/Nickster28/Maret-Calendar-Scraper'>" +
"our GitHub repo</a> for this project's code.</html>");
});
/* Start the server */
app.listen(app.get("port"), function() {
console.log("Node app is running on port", app.get("port"));
});