Add API route to get Protospace class list
This commit is contained in:
parent
18bae1f3d4
commit
7ab2a42348
|
@ -18,8 +18,10 @@
|
|||
"webpack-dev-server": "^2.4.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"cheerio": "^1.0.0-rc.1",
|
||||
"express": "^4.15.3",
|
||||
"react": "^15.6.1",
|
||||
"react-dom": "^15.6.1"
|
||||
"react-dom": "^15.6.1",
|
||||
"request": "^2.81.0"
|
||||
}
|
||||
}
|
||||
|
|
24
server.js
24
server.js
|
@ -1,12 +1,34 @@
|
|||
const request = require('request');
|
||||
const cheerio = require('cheerio');
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
|
||||
app.use('/', express.static('dist'))
|
||||
|
||||
app.get('/hello', function (req, res) {
|
||||
app.get('/hello', (req, res) => {
|
||||
res.send('Hello World!')
|
||||
})
|
||||
|
||||
app.get('/api/data/classes', (req, res) => {
|
||||
request('https://my.protospace.ca/school', (error, response, html) => {
|
||||
if (!error && response.statusCode == 200) {
|
||||
const $ = cheerio.load(html);
|
||||
let classes = [];
|
||||
|
||||
$('table.grid tbody tr').each((i, elem) => {
|
||||
classes[i] = {
|
||||
subject: $(elem).children().eq(0).text(),
|
||||
date: $(elem).children().eq(2).text(),
|
||||
available: $(elem).children().eq(6).text()
|
||||
}
|
||||
});
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(classes);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
app.listen(3000, function () {
|
||||
console.log('Example app listening on port 3000!')
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user