Skip to content

Commit b16857b

Browse files
committed
Fixed backend added github pages
1 parent c297f6d commit b16857b

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

api/routes.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,19 @@ router.get('/lectures/:course', (req, res) => {
5151
if (err) res.json(err);
5252
var response = [];
5353
data.forEach(e => response.push({start: e.dtstart, end: e.dtend, lastModified: e['last-modified'], title: e.summary, description: e.description, location: e.location, course: e.course}));
54-
if (res == null) res.json({error: "No course found or there are no lectures yet!"});
54+
if (res == []) res.json({error: "No course found or there are no lectures yet!"});
55+
else res.json(response);
56+
});
57+
});
58+
59+
router.get('/futureLectures/:course', (req, res) => {
60+
lecture.find({course: req.params.course.toUpperCase()}, (err, data) => {
61+
if (err) res.json(err);
62+
var response = [];
63+
data.forEach(e => {
64+
if((new Date(e.dtstart)) > (new Date())) response.push({start: e.dtstart, end: e.dtend, lastModified: e['last-modified'], title: e.summary, description: e.description, location: e.location, course: e.course});
65+
});
66+
if (res == []) res.json({error: "No course found or there are no lectures yet!"});
5567
else res.json(response);
5668
});
5769
});
@@ -78,7 +90,7 @@ router.get('/news', (req, res) => {
7890
feed.find((err, data) => {
7991
if (err) res.json(err);
8092
var response = [];
81-
data.forEach(e => response.push({title: e.title, description: e.description, url: e.url, created: new Date(e.created)}));
93+
data.forEach(e => response.push({title: e.title, description: e['content:encoded'], url: e.link, created: new Date(e.isoDate)}));
8294
res.json(response);
8395
});
8496
});

datacollectors/newsfeed/feed.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
var reader = require('rss-to-json');
1+
var Reader = require('rss-parser');
2+
var reader = new Reader();
23
var mongo = require('mongodb').MongoClient;
34
var dbProvider = require('../../utils/db');
45

@@ -7,11 +8,9 @@ var url_DB = dbProvider.getUrl();
78

89
var db_env = dbProvider.getEnv();
910

10-
const loadFeed = (url, resolve, reject) => {
11-
reader.load(url, (err, res) => {
12-
if (err) reject(err);
13-
updateEvents(res, resolve, reject);
14-
});
11+
const loadFeed = async (url, resolve, reject) => {
12+
let data = await reader.parseURL(url);
13+
updateEvents(data, resolve, reject);
1514
};
1615

1716
const updateEvents = (data, resolve, reject) => {
@@ -26,7 +25,7 @@ const updateEvents = (data, resolve, reject) => {
2625
counter++;
2726
if (res == null) {
2827
insertElement(e, dbo, resolve, reject);
29-
} else if (res.description != e.description) {
28+
} else if (res.content != e.content) {
3029
updateElement(e, dbo, resolve, reject);
3130
}
3231
if (counter >= data.items.length) {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"mongoose": "^5.4.18",
2121
"request": "^2.88.0",
2222
"request-promise": "^4.2.4",
23+
"rss-parser": "^3.7.0",
2324
"rss-to-json": "^1.0.4",
2425
"split-lines": "^2.0.0"
2526
}

utils/provider.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ var eventSchema = new Schema({
2222
});
2323

2424
var feedSchema = new Schema({
25+
creator: String,
2526
title: String,
26-
description: String,
2727
link: String,
28-
url: String,
29-
created: Number
28+
pubDate: String,
29+
'content:encoded': String,
30+
'dc:creator': String,
31+
content: String,
32+
contentSnippet: String,
33+
guid: String,
34+
isoDate: String
3035
});
3136

3237
var lectureSchema = new Schema({

0 commit comments

Comments
 (0)