Skip to content

Commit

Permalink
Added params for speiseplan. Integrated moment.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Wohlert committed Apr 29, 2016
1 parent c5176ed commit c2c898c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"request": "2.69.0",
"debug": "2.2.0",
"express": "4.13.4",
"moment": "2.13.0",
"extract-text-webpack-plugin": "1.0.1",
"mongoose": "4.4.4",
"morgan": "1.7.0",
Expand Down
11 changes: 10 additions & 1 deletion src/server/controller/api/cis/cisApiController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Userhelper = require('../../../helper/userHelper');
const requestmodule = require('request');
const cheerio = require('cheerio');
const speiseplanHelper = require('../../../helper/speiseplanHelper');
var moment = require('moment');

module.exports = (() => {
'use strict';
Expand Down Expand Up @@ -51,7 +52,15 @@ module.exports = (() => {
}

function speiseplan(request, response) {
requestmodule('https://cis.nordakademie.de/service/tp-mensa/speiseplan.cmd', function(error, request_response, html) {
let url = 'https://cis.nordakademie.de/service/tp-mensa/speiseplan.cmd';
if (request.query.week !== undefined && request.query.year !== undefined) {
console.log(request.query.week);
console.log(request.query.year);
url= url + '?date=' + moment(''.concat(request.query.year, '-W', request.query.week, '-6')).unix() + '999&action=show';
} else if (request.query.date !== undefined) {
url= url + '?date=' + request.query.date + '999&action=show';
}
requestmodule(url, function(error, request_response, html) {
if (!error && request_response.statusCode === 200) {
const $ = cheerio.load(html);
response.json(speiseplanHelper.getMeals($));
Expand Down
6 changes: 3 additions & 3 deletions src/server/helper/speiseplanHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ module.exports = (() => {
function getMeals(cheerioHandle) {
const arr = {};
let dayCounter = 0;
const Dates = getDates(cheerioHandle);
cheerioHandle('td.speiseplan-tag-container').each(function() {
const eachDayContent = {};
let mealCounter = 0;
eachDayContent.date = getDates(cheerioHandle)[dayCounter] + new Date().getFullYear();
cheerioHandle('td.speiseplan-tag', this).each(function(i, elem) {
eachDayContent.date = Dates[dayCounter] + new Date().getFullYear();
cheerioHandle('td.speiseplan-tag', this).each(function(id, elem) {
mealCounter += 1;
const mealName = 'meal'.concat(mealCounter);
eachDayContent[mealName] = meal(cheerioHandle, elem);
Expand All @@ -43,7 +44,6 @@ module.exports = (() => {
}

return {
getDates,
getMeals
};
})();

0 comments on commit c2c898c

Please sign in to comment.