Implemented configuration everywhere possible and added times to schedule.jade

This commit is contained in:
Bram van der Veen 2015-06-14 23:32:57 +02:00
parent 3eaf81b40f
commit 64857e8d48
6 changed files with 31 additions and 11 deletions

View file

@ -1,7 +1,9 @@
//lookup.js //lookup.js
var http = require('http'); var http = require('http');
var database = require('mongoskin').db('mongodb://wallpiece/roosterio'); var config = require('./configuration');
var schoolid = 934;
var database = require('mongoskin').db('mongodb://' + config().database);
var school_id = config().school_id;
//Function for looking through the database and finding entries related to the searchterm. //Function for looking through the database and finding entries related to the searchterm.
function lookup(req, res, next, search) { function lookup(req, res, next, search) {
@ -25,7 +27,7 @@ function lookup(req, res, next, search) {
//Function for making a link out of the given database_entry. //Function for making a link out of the given database_entry.
function make_url(database_entry) { function make_url(database_entry) {
var url = 'http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolid + '&type=' + database_entry.type.charAt(0).toUpperCase() + database_entry.type.slice(1) + 'rooster'; var url = 'http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + school_id + '&type=' + database_entry.type.charAt(0).toUpperCase() + database_entry.type.slice(1) + 'rooster';
switch (database_entry.type) { switch (database_entry.type) {
case 'leerling' : case 'leerling' :

View file

@ -16,6 +16,10 @@ div.schedule
span.teacher= hour.teacher span.teacher= hour.teacher
span.chamber= hour.chamber span.chamber= hour.chamber
span.course= hour.course span.course= hour.course
if match.json.indexOf(day) == 0
span.time= match.times[match.json[0].indexOf(hour)]
else else
div.hour.changed div.hour.changed
span.free Vrij span.free Vrij

View file

@ -62,12 +62,13 @@ div.schedule {
float: left; float: left;
div.hour { div.hour {
width: 150px;
height: 20px; height: 20px;
border-bottom: solid 1px #DDD; border-bottom: solid 1px #DDD;
padding: 12px 15px; padding: 12px 15px;
border-bottom: 1px solid #e1e1e1; border-bottom: 1px solid #e1e1e1;
width: 150px;
border-left: 1px solid #FFF; border-left: 1px solid #FFF;
position: relative;
span { span {
display: inline-block; display: inline-block;
@ -101,6 +102,15 @@ div.schedule {
} }
} }
.time {
font-size: 10px;
color: #665;
width: 100%;
position: absolute;
top: 2px;
left: 5px;
}
.free { .free {
.changed; .changed;
text-align: center; text-align: center;

View file

@ -1,11 +1,13 @@
//schedule.js //schedule.js
var http = require('http'); var http = require('http');
var cheerio = require('cheerio'); var cheerio = require('cheerio');
var config = require('./configuration');
//Wrapper function that is being called by express. //Wrapper function that is being called by express.
function schedule(req, res, next) { function schedule(req, res, next) {
get(req.match.url, function (json) { get(req.match.url, function (json) {
req.match.json = json; req.match.json = json;
req.match.times = config().hour_times;
next(); next();
}); });
} }
@ -29,7 +31,7 @@ function get(url, callback) {
function to_json(page) { function to_json(page) {
var result = cheerio('td:nth-child(3) table', page); var result = cheerio('td:nth-child(3) table', page);
var amount_of_days = cheerio(result).find('tr.AccentDark').find('td').length - 1; var amount_of_days = cheerio(result).find('tr.AccentDark').find('td').length - 1;
var amount_of_hours = 7; var amount_of_hours = config().amount_of_hours;
var schedule_data = []; var schedule_data = [];

View file

@ -2,6 +2,7 @@ var http = require('http');
var cheerio = require('cheerio'); var cheerio = require('cheerio');
var iconv = require('iconv-lite'); var iconv = require('iconv-lite');
var mongodb = require('mongodb').MongoClient; var mongodb = require('mongodb').MongoClient;
var config = require('./configuration');
var scheduletypes = [ var scheduletypes = [
'Klasrooster', 'Klasrooster',
@ -110,9 +111,9 @@ function rip(data) {
} }
//Function being called to access functionality from this module. //Function being called to access functionality from this module.
function crawl(sid) { function crawl() {
school_id = sid; school_id = config().school_id;
mongodb.connect('mongodb://wallpiece/roosterio', function (error, db) { mongodb.connect('mongodb://' + config().database, function (error, db) {
if (error) console.warn(error); if (error) console.warn(error);
database = db; database = db;

7
web.js
View file

@ -1,10 +1,11 @@
//web.js //web.js
var config = require('./configuration');
var express = require('express'); var express = require('express');
var less = require('express-less'); var less = require('express-less');
var app = express(); var app = express();
var lookup = require('./lookup.js'); var lookup = require('./lookup');
var schedule = require('./schedule.js'); var schedule = require('./schedule');
app.set('view engine', 'jade'); app.set('view engine', 'jade');
app.disable('view cache'); app.disable('view cache');
@ -37,4 +38,4 @@ app.param('search', function (req, res) {
console.log(req); console.log(req);
}); });
app.listen(1024); app.listen(config().web_port);