mirror of
https://gitlab.silvrtree.co.uk/martind2000/old-silvrgit.git
synced 2025-01-10 21:55:08 +00:00
updated work calendar link
This commit is contained in:
parent
62e3c8711e
commit
929904325f
776
app/app.js
776
app/app.js
@ -1,476 +1,388 @@
|
||||
(function () {
|
||||
|
||||
var lastGBP = 0.0,
|
||||
lastUSD = 0.0,
|
||||
_fasttimer, _slowTimer, myBTC =3.49524333;
|
||||
var lows = {
|
||||
gbp: 0,
|
||||
usd: 0
|
||||
},
|
||||
highs = {
|
||||
gbp: 0,
|
||||
usd: 0
|
||||
};
|
||||
|
||||
|
||||
var list = [{
|
||||
title: '101B ends',
|
||||
y: 2013,
|
||||
m: 9,
|
||||
d: 24,
|
||||
add: 1001
|
||||
},
|
||||
{
|
||||
title: 'Ends',
|
||||
y: 2016,
|
||||
m: 4,
|
||||
d: 4
|
||||
}];
|
||||
var addDays = function (myDate, days) {
|
||||
return new Date(myDate.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
var lastGBP = 0.0,
|
||||
lastUSD = 0.0,
|
||||
_fasttimer, _slowTimer, myBTC = 3.49524333;
|
||||
var lows = {
|
||||
gbp: 0,
|
||||
usd: 0
|
||||
},
|
||||
highs = {
|
||||
gbp: 0,
|
||||
usd: 0
|
||||
};
|
||||
|
||||
var getDays = function (startdate, enddate) {
|
||||
var r, s, e;
|
||||
s = startdate.getTime();
|
||||
e = enddate.getTime();
|
||||
r = (e - s) / (24 * 60 * 60 * 1000);
|
||||
return r;
|
||||
};
|
||||
var tick = function () {
|
||||
var today = new Date();
|
||||
var start101 = new Date();
|
||||
var end101 = new Date();
|
||||
var endContract = new Date();
|
||||
var third = new Date();
|
||||
start101.setFullYear(2013, 9, 24);
|
||||
end101 = addDays(start101, 1001);
|
||||
endContract.setFullYear(2016, 4, 4);
|
||||
third.setFullYear(2013, 7, 25);
|
||||
$('#one').text('101B ends: ' + Math.ceil(getDays(today,
|
||||
end101)) + " days / " + Math.ceil(getDays(today,
|
||||
end101) / 7) + " weeks");
|
||||
$('#two').text('Ends: ' + Math.ceil(getDays(today,
|
||||
endContract)) + " days / " + Math.ceil(getDays(today,
|
||||
endContract) / 7) + " weeks");
|
||||
$('#three').hide();
|
||||
};
|
||||
|
||||
var get_weather = function () {
|
||||
navigator.geolocation.getCurrentPosition(show_weather);
|
||||
};
|
||||
var show_weather = function (position) {
|
||||
var latitude = position.coords.latitude;
|
||||
var longitude = position.coords.longitude;
|
||||
// let's show a map or do something interesting!
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'https://api.forecast.io/forecast/0657dc0d81c037cbc89ca88e383b6bbf/' + latitude.toString() + ',' + longitude.toString() + '?units=uk2',
|
||||
data: '',
|
||||
dataType: 'jsonp',
|
||||
timeout: 10000,
|
||||
context: $('body'),
|
||||
contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
// console.log(data);
|
||||
|
||||
var calc = ((5.0 / 9.0 * (data.currently.temperature - 32)));
|
||||
$('#weather').html(data.currently.summary + " " + parseInt(calc) + '°c ' + '<em>' + data.daily.summary + '</em>');
|
||||
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var updateBTC = function (g, u) {
|
||||
var title, total, elm = $('#btc');
|
||||
if (lastGBP !== 0) {
|
||||
|
||||
elm.removeClass();
|
||||
if (g > lastGBP) {
|
||||
elm.addClass('up');
|
||||
} else if (g < lastGBP) {
|
||||
elm.addClass('down');
|
||||
}
|
||||
|
||||
} else {
|
||||
lows.gbp = g;
|
||||
lows.usd = u;
|
||||
|
||||
highs.gbp = g;
|
||||
highs.usd = u;
|
||||
}
|
||||
|
||||
lastGBP = g;
|
||||
lastUSD = u;
|
||||
|
||||
if (g < lows.gbp) lows.gbp = g;
|
||||
if (u < lows.usd) lows.usd = u;
|
||||
|
||||
if (highs.gbp < g) highs.gbp = g;
|
||||
if (highs.usd < u) highs.usd = u;
|
||||
|
||||
total = myBTC * g;
|
||||
|
||||
title = "High: $" + parseFloat(highs.usd.toFixed(2)) + " / Low $" + parseFloat(lows.usd.toFixed(2));
|
||||
elm.html("$" + parseFloat(u.toFixed(2)) + " / £" + parseFloat(g.toFixed(2)) + " (£" + parseFloat(total.toFixed(2)) + ")");
|
||||
|
||||
elm.prop('title', title);
|
||||
};
|
||||
|
||||
|
||||
var updateFX = function (data) {
|
||||
var title, total, elm = $('#fx');
|
||||
//title = "High: $" + parseFloat(highs.usd.toFixed(2)) + " / Low $" + parseFloat(lows.usd.toFixed(2));
|
||||
elm.html("£1 = $" + parseFloat(data.gpbe.toFixed(2)) + " = " + parseFloat(data.sekex.toFixed(2)) + " SEK");
|
||||
|
||||
// elm.prop('title', title);
|
||||
};
|
||||
|
||||
|
||||
var btcValue = function () {
|
||||
var url = '/btc';
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
timeout: 10000,
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
// console.log(data);
|
||||
var gbp = data.bpi.GBP.rate_float,
|
||||
usd = data.bpi.USD.rate_float;
|
||||
|
||||
updateBTC(gbp, usd);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var getFX = function () {
|
||||
var url = '/fx';
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
timeout: 10000,
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
//console.log(data);
|
||||
var gpbex = (1 / data.rates.GBP);
|
||||
var sekex = (gpbex * data.rates.SEK);
|
||||
var fxdata = {
|
||||
usd: 1,
|
||||
gbp: data.rates.GBP,
|
||||
sek: data.rates.SEK,
|
||||
gpbe: gpbex,
|
||||
sekex: sekex
|
||||
};
|
||||
// console.log(fxdata);
|
||||
//var fxdata = data.bpi.GBP.rate_float, usd = data.bpi.USD.rate_float;
|
||||
|
||||
updateFX(fxdata);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var getNextTrainTime = function(toStation,fromStation)
|
||||
var list = [{
|
||||
title: '101B ends',
|
||||
y: 2013,
|
||||
m: 9,
|
||||
d: 24,
|
||||
add: 1001
|
||||
},
|
||||
{
|
||||
var url = '/getnexttraintimes?from=' + fromStation + '&to=' + toStation ;
|
||||
var target = fromStation + toStation;
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
title: 'Ends',
|
||||
y: 2016,
|
||||
m: 4,
|
||||
d: 4
|
||||
}];
|
||||
|
||||
timeout: 10000,
|
||||
MicroEvent.mixin(this);
|
||||
var self = this;
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
var addDays = function (myDate, days) {
|
||||
return new Date(myDate.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
};
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
var getDays = function (startdate, enddate) {
|
||||
var r, s, e;
|
||||
s = startdate.getTime();
|
||||
e = enddate.getTime();
|
||||
r = (e - s) / (24 * 60 * 60 * 1000);
|
||||
return r;
|
||||
};
|
||||
|
||||
updateTrain(target,data);
|
||||
//updateFX(fxdata);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
var tick = function () {
|
||||
var today = new Date();
|
||||
var start101 = new Date();
|
||||
var end101;
|
||||
var endContract = new Date();
|
||||
var third = new Date();
|
||||
start101.setFullYear(2013, 9, 24);
|
||||
end101 = addDays(start101, 1001);
|
||||
endContract.setFullYear(2016, 4, 4);
|
||||
third.setFullYear(2013, 7, 25);
|
||||
$('#one').text('101B ends: ' + Math.ceil(getDays(today,
|
||||
end101)) + " days / " + Math.ceil(getDays(today,
|
||||
end101) / 7) + " weeks");
|
||||
$('#two').text('Ends: ' + Math.ceil(getDays(today,
|
||||
endContract)) + " days / " + Math.ceil(getDays(today,
|
||||
endContract) / 7) + " weeks");
|
||||
$('#three').hide();
|
||||
};
|
||||
|
||||
};
|
||||
var get_weather = function () {
|
||||
navigator.geolocation.getCurrentPosition(show_weather);
|
||||
};
|
||||
|
||||
this.bind('displayWeather', function (data) {
|
||||
$('#weather').html(data.currently.summary + ' ' + data.currently.temperature + '°c <em>' + data.daily.summary + '</em>');
|
||||
});
|
||||
|
||||
var show_weather = function (position) {
|
||||
var latitude = position.coords.latitude;
|
||||
var longitude = position.coords.longitude;
|
||||
// let's show a map or do something interesting!
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'https://api.forecast.io/forecast/0657dc0d81c037cbc89ca88e383b6bbf/' + latitude.toString() + ',' + longitude.toString() + '?units=uk2',
|
||||
data: '',
|
||||
dataType: 'jsonp',
|
||||
timeout: 10000,
|
||||
context: $('body'),
|
||||
contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
var getDBEGLQ = function () {
|
||||
},
|
||||
success: function (data) {
|
||||
self.trigger('displayWeather', data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// var url = '/dbeglq';
|
||||
var url = '/getnexttraintimes?from=dbe&to=glq';
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
var updateBTC = function (g, u) {
|
||||
var title, total, elm = $('#btc');
|
||||
if (lastGBP !== 0) {
|
||||
|
||||
timeout: 10000,
|
||||
elm.removeClass();
|
||||
if (g > lastGBP) {
|
||||
elm.addClass('up');
|
||||
} else if (g < lastGBP) {
|
||||
elm.addClass('down');
|
||||
}
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
} else {
|
||||
lows.gbp = g;
|
||||
lows.usd = u;
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
highs.gbp = g;
|
||||
highs.usd = u;
|
||||
}
|
||||
|
||||
updateTrain('dbeglq',data);
|
||||
//updateFX(fxdata);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
lastGBP = g;
|
||||
lastUSD = u;
|
||||
|
||||
var getGLQDBE = function () {
|
||||
if (g < lows.gbp) lows.gbp = g;
|
||||
if (u < lows.usd) lows.usd = u;
|
||||
|
||||
//var url = '/glqdbe';
|
||||
var url = '/getnexttraintimes?from=glq&to=dbe';
|
||||
if (highs.gbp < g) highs.gbp = g;
|
||||
if (highs.usd < u) highs.usd = u;
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
total = myBTC * g;
|
||||
|
||||
timeout: 10000,
|
||||
title = "High: $" + parseFloat(highs.usd.toFixed(2)) + " / Low $" + parseFloat(lows.usd.toFixed(2));
|
||||
elm.html("$" + parseFloat(u.toFixed(2)) + " / £" + parseFloat(g.toFixed(2)) + " (£" + parseFloat(total.toFixed(2)) + ")");
|
||||
elm.prop('title', title);
|
||||
};
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
var updateFX = function (data) {
|
||||
var elm = $('#fx');
|
||||
elm.html("£1 = $" + parseFloat(data.gpbe.toFixed(2)) + " = " + parseFloat(data.sekex.toFixed(2)) + " SEK");
|
||||
};
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
var btcValue = function () {
|
||||
var url = '/btc';
|
||||
|
||||
updateTrain('glqdbe',data);
|
||||
//updateFX(fxdata);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
var updateTrain = function (n, obj) {
|
||||
var elm = $('#'+n);
|
||||
timeout: 10000,
|
||||
|
||||
var output, status;
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
// console.log(data);
|
||||
var gbp = data.bpi.GBP.rate_float,
|
||||
usd = data.bpi.USD.rate_float;
|
||||
|
||||
output = (obj.eta == "On Time") ? obj.eta : obj.sta;
|
||||
status = (obj.eta == "On Time") ? 'delayed' : 'ontime';
|
||||
updateBTC(gbp, usd);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
elm.html(output);
|
||||
|
||||
elm.prop('class', status);
|
||||
};
|
||||
|
||||
var getTrainsCB = function (results) {
|
||||
var dest$ = $('#trainResults');
|
||||
var html = new EJS({url: '/template/trains.ejs'}).render(results);
|
||||
|
||||
console.log(html);
|
||||
dest$.empty();
|
||||
dest$.append(html);
|
||||
dest$.toggle();
|
||||
|
||||
};
|
||||
|
||||
var getTrains = function(from, to) {
|
||||
var url = '/gettrains?from=' + from + "&to=" + to;
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
timeout: 10000,
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
|
||||
// updateTrain('glqdbe',data);
|
||||
getTrainsCB(data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var formatPassword = function (data) {
|
||||
|
||||
|
||||
var dest$ = $('#passwordOut');
|
||||
var html = new EJS({url: '/template/password.ejs'}).render(data);
|
||||
|
||||
console.log(html);
|
||||
dest$.empty();
|
||||
dest$.append(html);
|
||||
dest$.show();
|
||||
};
|
||||
|
||||
|
||||
var generatePassword = function(from, to) {
|
||||
var url = '/generate';
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
timeout: 10000,
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
|
||||
formatPassword(data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
tick();
|
||||
get_weather();
|
||||
this.bind('getBTC', function () {
|
||||
btcValue();
|
||||
});
|
||||
|
||||
var getFX = function () {
|
||||
var url = '/fx';
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
timeout: 10000,
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
//console.log(data);
|
||||
var gpbex = (1 / data.rates.GBP);
|
||||
var sekex = (gpbex * data.rates.SEK);
|
||||
var fxdata = {
|
||||
usd: 1,
|
||||
gbp: data.rates.GBP,
|
||||
sek: data.rates.SEK,
|
||||
gpbe: gpbex,
|
||||
sekex: sekex
|
||||
};
|
||||
// console.log(fxdata);
|
||||
//var fxdata = data.bpi.GBP.rate_float, usd = data.bpi.USD.rate_float;
|
||||
|
||||
updateFX(fxdata);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var getNextTrainTime = function (toStation, fromStation) {
|
||||
var url = '/getnexttraintimes?from=' + fromStation + '&to=' + toStation;
|
||||
var target = fromStation + toStation;
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
timeout: 10000,
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
},
|
||||
success: function (data) {
|
||||
updateTrain(target, data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var updateTrain = function (n, obj) {
|
||||
var elm = $('#' + n);
|
||||
|
||||
var output, status;
|
||||
|
||||
output = (obj.eta == "On Time") ? obj.eta : obj.sta;
|
||||
status = (obj.eta == "On Time") ? 'delayed' : 'ontime';
|
||||
|
||||
elm.html(output);
|
||||
elm.prop('class', status);
|
||||
};
|
||||
|
||||
var getTrainsCB = function (results) {
|
||||
var dest$ = $('#trainResults');
|
||||
var html = new EJS({url: '/template/trains.ejs'}).render(results);
|
||||
|
||||
dest$.empty();
|
||||
dest$.append(html);
|
||||
dest$.toggle();
|
||||
};
|
||||
|
||||
var getTrains = function (from, to) {
|
||||
var url = '/gettrains?from=' + from + "&to=" + to;
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
getTrainsCB(data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var formatPassword = function (data) {
|
||||
|
||||
var dest$ = $('#passwordOut');
|
||||
var html = new EJS({url: '/template/password.ejs'}).render(data);
|
||||
dest$.empty();
|
||||
dest$.append(html);
|
||||
dest$.show();
|
||||
};
|
||||
|
||||
var generatePassword = function (from, to) {
|
||||
var url = '/generate';
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
timeout: 10000,
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
formatPassword(data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
tick();
|
||||
get_weather();
|
||||
self.trigger('getBTC');
|
||||
getFX();
|
||||
getNextTrainTime('dbe', 'glq');
|
||||
getNextTrainTime('glq', 'dbe');
|
||||
|
||||
// start 15 minute timer
|
||||
|
||||
_fastTimer = setInterval(function () {
|
||||
self.trigger('getBTC');
|
||||
getNextTrainTime('dbe', 'glq');
|
||||
getNextTrainTime('glq', 'dbe');
|
||||
}, (60000));
|
||||
|
||||
_slowTimer = setInterval(function () {
|
||||
|
||||
getFX();
|
||||
//getDBEGLQ();
|
||||
//getGLQDBE();
|
||||
getNextTrainTime('dbe','glq');
|
||||
getNextTrainTime('glq','dbe');
|
||||
get_weather();
|
||||
}, (60000 * 15));
|
||||
|
||||
// start 15 minute timer
|
||||
$('#dbeglq').on('click', function () {
|
||||
self.trigger('getTrains', 'dbe', 'glq');
|
||||
});
|
||||
|
||||
_fastTimer = setInterval(function () {
|
||||
btcValue();
|
||||
// getDBEGLQ();
|
||||
// getGLQDBE();
|
||||
getNextTrainTime('dbe','glq');
|
||||
getNextTrainTime('glq','dbe');
|
||||
}, (60000));
|
||||
$('#glqdbe').on('click', function () {
|
||||
self.trigger('getTrains', 'glq', 'dbe');
|
||||
});
|
||||
|
||||
_slowTimer = setInterval(function () {
|
||||
$('#newPassword').on('click', function () {
|
||||
generatePassword();
|
||||
});
|
||||
|
||||
getFX();
|
||||
get_weather();
|
||||
}, (60000 * 15));
|
||||
|
||||
$('#dbeglq').on('click',function(){
|
||||
getTrains('dbe','glq');
|
||||
});
|
||||
|
||||
$('#glqdbe').on('click',function(){
|
||||
getTrains('glq','dbe');
|
||||
});
|
||||
|
||||
$('#newPassword').on('click', function() {
|
||||
generatePassword();
|
||||
});
|
||||
this.bind('getTrains', function (start, end) {
|
||||
getTrains(start, end);
|
||||
});
|
||||
|
||||
document.title = 'Slack';
|
||||
})();
|
||||
|
||||
var popitout = function (url) {
|
||||
newwindow = window.open(url, 'name', 'height=600,width=570');
|
||||
if (window.focus) {
|
||||
newwindow.focus()
|
||||
}
|
||||
return false;
|
||||
var newwindow = window.open(url, 'name', 'height=600,width=570');
|
||||
if (window.focus) {
|
||||
newwindow.focus()
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
var popitoutSmall = function (url) {
|
||||
newwindow = window.open(url, 'name', 'height=400,width=520');
|
||||
if (window.focus) {
|
||||
newwindow.focus()
|
||||
}
|
||||
return false;
|
||||
var newwindow = window.open(url, 'name', 'height=400,width=520');
|
||||
if (window.focus) {
|
||||
newwindow.focus()
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
12
app/app.min.js
vendored
12
app/app.min.js
vendored
@ -1,2 +1,10 @@
|
||||
!function(){var e,o=0,t=0,n=3.49524333,a={gbp:0,usd:0},s={gbp:0,usd:0},r=function(e,o){return new Date(e.getTime()+24*o*60*60*1e3)},c=function(e,o){var t,n,a;return n=e.getTime(),a=o.getTime(),t=(a-n)/864e5},l=function(){var e=new Date,o=new Date,t=new Date,n=new Date,a=new Date;o.setFullYear(2013,9,24),t=r(o,1001),n.setFullYear(2015,4,10),a.setFullYear(2013,7,25),$("#one").text("101B ends: "+Math.ceil(c(e,t))+" days / "+Math.ceil(c(e,t)/7)+" weeks"),$("#two").text("Ends: "+Math.ceil(c(e,n))+" days / "+Math.ceil(c(e,n)/7)+" weeks"),$("#three").hide()},i=function(){navigator.geolocation.getCurrentPosition(p)},p=function(e){var o=e.coords.latitude,t=e.coords.longitude;$.ajax({type:"GET",url:"https://api.forecast.io/forecast/0657dc0d81c037cbc89ca88e383b6bbf/"+o.toString()+","+t.toString(),data:"",dataType:"jsonp",timeout:1e4,context:$("body"),contentType:"application/json",headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){var o=5/9*(e.currently.temperature-32);$("#weather").html(e.currently.summary+" "+parseInt(o)+"°c <em>"+e.daily.summary+"</em>")},error:function(e,o){console.log("ajax error"),console.log(e),console.log(o)}})},u=function(e,r){var c,l,i=$("#btc");0!==o?(i.removeClass(),e>o?i.addClass("up"):o>e&&i.addClass("down")):(a.gbp=e,a.usd=r,s.gbp=e,s.usd=r),o=e,t=r,e<a.gbp&&(a.gbp=e),r<a.usd&&(a.usd=r),s.gbp<e&&(s.gbp=e),s.usd<r&&(s.usd=r),l=n*e,c="High: $"+parseFloat(s.usd.toFixed(2))+" / Low $"+parseFloat(a.usd.toFixed(2)),i.html("$"+parseFloat(r.toFixed(2))+" / £"+parseFloat(e.toFixed(2))+" (£"+parseFloat(l.toFixed(2))+")"),i.prop("title",c)},d=function(e){var o=$("#fx");o.html("£1 = $"+parseFloat(e.gpbe.toFixed(2))+" = "+parseFloat(e.sekex.toFixed(2))+" SEK")},h=function(){var e="/btc";$.ajax({type:"GET",url:e,data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){var o=e.bpi.GBP.rate_float,t=e.bpi.USD.rate_float;u(o,t)},error:function(e,o){console.log("ajax error"),console.log(e),console.log(o)}})},g=function(){var e="/fx";$.ajax({type:"GET",url:e,data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){var o=1/e.rates.GBP,t=o*e.rates.SEK,n={usd:1,gbp:e.rates.GBP,sek:e.rates.SEK,gpbe:o,sekex:t};d(n)},error:function(e,o){console.log("ajax error"),console.log(e),console.log(o)}})},f=function(){var e="/dbeglq";$.ajax({type:"GET",url:e,data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){console.log(e),v("dbeglq",e)},error:function(e,o){console.log("ajax error"),console.log(e),console.log(o)}})},b=function(){var e="/glqdbe";$.ajax({type:"GET",url:e,data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){console.log(e),v("glqdbe",e)},error:function(e,o){console.log("ajax error"),console.log(e),console.log(o)}})},v=function(e,o){var t,n,a=$("#"+e);t="On Time"==o.eta?o.eta:o.sta,n="On Time"==o.eta?"delayed":"ontime",a.html(t),a.prop("class",n)};l(),i(),h(),g(),f(),b(),_fastTimer=setInterval(function(){h(),f(),b()},6e4),e=setInterval(function(){g(),i()},9e5)}();var popitout=function(e){return newwindow=window.open(e,"name","height=600,width=570"),window.focus&&newwindow.focus(),!1},popitoutSmall=function(e){return newwindow=window.open(e,"name","height=400,width=520"),window.focus&&newwindow.focus(),!1};
|
||||
//# sourceMappingURL=app.min.js.map
|
||||
(function(){var c=0,m=0,g=0,n=0,h=0;MicroEvent.mixin(this);var e=this,k=function(a,b){var d;d=a.getTime();return(b.getTime()-d)/864E5};this.bind("displayWeather",function(a){console.log("Update weather event:");$("#weather").html(a.currently.summary+" "+a.currently.temperature+"°c <em>"+a.daily.summary+"</em>")});var p=function(a){$.ajax({type:"GET",url:"https://api.forecast.io/forecast/0657dc0d81c037cbc89ca88e383b6bbf/"+a.coords.latitude.toString()+","+a.coords.longitude.toString()+"?units=uk2",
|
||||
data:"",dataType:"jsonp",timeout:1E4,context:$("body"),contentType:"application/json",headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(a){e.trigger("displayWeather",a)},error:function(a,d){console.log("ajax error");console.log(a);console.log(d)}})},t=function(){$.ajax({type:"GET",url:"/btc",data:"",dataType:"json",timeout:1E4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS",
|
||||
"Access-Control-Allow-Headers":"Content-Type"},success:function(a){var b=a.bpi.GBP.rate_float;a=a.bpi.USD.rate_float;var d,q,f=$("#btc");0!==c?(f.removeClass(),b>c?f.addClass("up"):b<c&&f.addClass("down")):(m=b,g=a,n=b,h=a);c=b;b<m&&(m=b);a<g&&(g=a);n<b&&(n=b);h<a&&(h=a);q=3.49524333*b;d="High: $"+parseFloat(h.toFixed(2))+" / Low $"+parseFloat(g.toFixed(2));f.html("$"+parseFloat(a.toFixed(2))+" / £"+parseFloat(b.toFixed(2))+" (£"+parseFloat(q.toFixed(2))+")");f.prop("title",d)},error:function(a,
|
||||
b){console.log("ajax error");console.log(a);console.log(b)}})};this.bind("getBTC",function(){console.log("BTC Event");t()});var r=function(){$.ajax({type:"GET",url:"/fx",data:"",dataType:"json",timeout:1E4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(a){var b=1/a.rates.GBP;a=b*a.rates.SEK;$("#fx").html("£1 = $"+parseFloat(b.toFixed(2))+" = "+parseFloat(a.toFixed(2))+
|
||||
" SEK")},error:function(a,b){console.log("ajax error");console.log(a);console.log(b)}})},l=function(a,b){var d=b+a;$.ajax({type:"GET",url:"/getnexttraintimes?from="+b+"&to="+a,data:"",dataType:"json",timeout:1E4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(a){var b=$("#"+d),c;c="On Time"==a.eta?a.eta:a.sta;a="On Time"==a.eta?"delayed":"ontime";b.html(c);b.prop("class",a)},
|
||||
error:function(a,b){console.log("ajax error");console.log(a);console.log(b)}})},u=function(a,b){$.ajax({type:"GET",url:"/gettrains?from="+a+"&to="+b,data:"",dataType:"json",timeout:1E4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(a){var b=$("#trainResults");a=(new EJS({url:"/template/trains.ejs"})).render(a);b.empty();b.append(a);b.toggle()},error:function(a,b){console.log("ajax error");
|
||||
console.log(a);console.log(b)}})},v=function(a,b){$.ajax({type:"GET",url:"/generate",data:"",dataType:"json",timeout:1E4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(a){var b=$("#passwordOut");a=(new EJS({url:"/template/password.ejs"})).render(a);b.empty();b.append(a);b.show()},error:function(a,b){console.log("ajax error");console.log(a);console.log(b)}})};(function(){var a=
|
||||
new Date,b=new Date,c=new Date,e=new Date;b.setFullYear(2013,9,24);b=new Date(b.getTime()+864864E5);c.setFullYear(2016,4,4);e.setFullYear(2013,7,25);$("#one").text("101B ends: "+Math.ceil(k(a,b))+" days / "+Math.ceil(k(a,b)/7)+" weeks");$("#two").text("Ends: "+Math.ceil(k(a,c))+" days / "+Math.ceil(k(a,c)/7)+" weeks");$("#three").hide()})();navigator.geolocation.getCurrentPosition(p);e.trigger("getBTC");r();l("dbe","glq");l("glq","dbe");_fastTimer=setInterval(function(){e.trigger("getBTC");l("dbe",
|
||||
"glq");l("glq","dbe")},6E4);setInterval(function(){r();navigator.geolocation.getCurrentPosition(p)},9E5);$("#dbeglq").on("click",function(){e.trigger("getTrains","dbe","glq")});$("#glqdbe").on("click",function(){e.trigger("getTrains","glq","dbe")});$("#newPassword").on("click",function(){v()});this.bind("getTrains",function(a,b){u(a,b)});document.title="Slack"})();
|
||||
var popitout=function(c){c=window.open(c,"name","height=600,width=570");window.focus&&c.focus();return!1},popitoutSmall=function(c){c=window.open(c,"name","height=400,width=520");window.focus&&c.focus();return!1};
|
||||
|
55
app/libs/microevent.js
Normal file
55
app/libs/microevent.js
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* MicroEvent - to make any js object an event emitter (server or browser)
|
||||
*
|
||||
* - pure javascript - server compatible, browser compatible
|
||||
* - dont rely on the browser doms
|
||||
* - super simple - you get it immediatly, no mistery, no magic involved
|
||||
*
|
||||
* - create a MicroEventDebug with goodies to debug
|
||||
* - make it safer to use
|
||||
*/
|
||||
|
||||
var MicroEvent = function(){};
|
||||
MicroEvent.prototype = {
|
||||
bind : function(event, fct){
|
||||
this._events = this._events || {};
|
||||
this._events[event] = this._events[event] || [];
|
||||
this._events[event].push(fct);
|
||||
},
|
||||
unbind : function(event, fct){
|
||||
this._events = this._events || {};
|
||||
if( event in this._events === false ) return;
|
||||
this._events[event].splice(this._events[event].indexOf(fct), 1);
|
||||
},
|
||||
trigger : function(event /* , args... */){
|
||||
this._events = this._events || {};
|
||||
if( event in this._events === false ) return;
|
||||
for(var i = 0; i < this._events[event].length; i++){
|
||||
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* mixin will delegate all MicroEvent.js function in the destination object
|
||||
*
|
||||
* - require('MicroEvent').mixin(Foobar) will make Foobar able to use MicroEvent
|
||||
*
|
||||
* @param {Object} the object which will support MicroEvent
|
||||
*/
|
||||
MicroEvent.mixin = function(destObject){
|
||||
var props = ['bind', 'unbind', 'trigger'];
|
||||
for(var i = 0; i < props.length; i ++){
|
||||
if( typeof destObject === 'function' ){
|
||||
destObject.prototype[props[i]] = MicroEvent.prototype[props[i]];
|
||||
}else{
|
||||
destObject[props[i]] = MicroEvent.prototype[props[i]];
|
||||
}
|
||||
}
|
||||
return destObject;
|
||||
}
|
||||
|
||||
// export in common js
|
||||
if( typeof module !== "undefined" && ('exports' in module)){
|
||||
module.exports = MicroEvent;
|
||||
}
|
55
lib/microevent.js
Normal file
55
lib/microevent.js
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* MicroEvent - to make any js object an event emitter (server or browser)
|
||||
*
|
||||
* - pure javascript - server compatible, browser compatible
|
||||
* - dont rely on the browser doms
|
||||
* - super simple - you get it immediatly, no mistery, no magic involved
|
||||
*
|
||||
* - create a MicroEventDebug with goodies to debug
|
||||
* - make it safer to use
|
||||
*/
|
||||
|
||||
var MicroEvent = function(){};
|
||||
MicroEvent.prototype = {
|
||||
bind : function(event, fct){
|
||||
this._events = this._events || {};
|
||||
this._events[event] = this._events[event] || [];
|
||||
this._events[event].push(fct);
|
||||
},
|
||||
unbind : function(event, fct){
|
||||
this._events = this._events || {};
|
||||
if( event in this._events === false ) return;
|
||||
this._events[event].splice(this._events[event].indexOf(fct), 1);
|
||||
},
|
||||
trigger : function(event /* , args... */){
|
||||
this._events = this._events || {};
|
||||
if( event in this._events === false ) return;
|
||||
for(var i = 0; i < this._events[event].length; i++){
|
||||
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* mixin will delegate all MicroEvent.js function in the destination object
|
||||
*
|
||||
* - require('MicroEvent').mixin(Foobar) will make Foobar able to use MicroEvent
|
||||
*
|
||||
* @param {Object} the object which will support MicroEvent
|
||||
*/
|
||||
MicroEvent.mixin = function(destObject){
|
||||
var props = ['bind', 'unbind', 'trigger'];
|
||||
for(var i = 0; i < props.length; i ++){
|
||||
if( typeof destObject === 'function' ){
|
||||
destObject.prototype[props[i]] = MicroEvent.prototype[props[i]];
|
||||
}else{
|
||||
destObject[props[i]] = MicroEvent.prototype[props[i]];
|
||||
}
|
||||
}
|
||||
return destObject;
|
||||
}
|
||||
|
||||
// export in common js
|
||||
if( typeof module !== "undefined" && ('exports' in module)){
|
||||
module.exports = MicroEvent;
|
||||
}
|
@ -106,6 +106,7 @@ Array.prototype.indexOf = function (e, fn) {
|
||||
|
||||
module.exports = {
|
||||
getToday: function (req, res) {
|
||||
console.log(todayCache);
|
||||
res.render('pages/today', todayCache);
|
||||
},
|
||||
getTodayDate: function () {
|
||||
|
49
recipes.json
Normal file
49
recipes.json
Normal file
@ -0,0 +1,49 @@
|
||||
{"recipes":[
|
||||
{"url":"", "title":""},
|
||||
|
||||
|
||||
{"url":"http://www.simplyrecipes.com/recipes/grilled_lime_chicken_with_black_bean_sauce/", "title":"Grilled Lime Chicken with Black Bean Sauce Recipe"},
|
||||
{"url":"http://www.marksdailyapple.com/shakshuka-eggs-poached-in-spicy-tomato-sauce/#axzz29jTSubMo", "title":"Shakshuka (Eggs Poached in Spicy Tomato Sauce) "},
|
||||
{"url":"http://www.marksdailyapple.com/spiced-pork-and-butternut-squash-with-sage/#axzz29jTSubMo", "title":"Spiced Pork and Butternut Squash with Sage"},
|
||||
{"url":"http://www.marksdailyapple.com/dairy-free-green-goddess-dressing/#axzz29jTSubMo", "title":"Dairy-Free Green Goddess Dressing"},
|
||||
{"url":"http://www.marksdailyapple.com/pork-stuffed-jalapeno-peppers/#axzz29jTSubMo", "title":"Pork-Stuffed Jalapeño Peppers"},
|
||||
{"url":"http://www.marksdailyapple.com/herb-chicken-cooked-under-a-brick/#axzz29jTSubMo", "title":"Herb Chicken Cooked Under a Brick"},
|
||||
{"url":"http://www.marksdailyapple.com/balsamic-glazed-drumsticks/#axzz29jTSubMo", "title":"Balsamic-Glazed Drumsticks"},
|
||||
{"url":"http://www.marksdailyapple.com/slow-cooked-coconut-ginger-pork/#axzz29jTSubMo", "title":"Slow-Cooked Coconut Ginger Pork"},
|
||||
{"url":"http://www.marksdailyapple.com/lime-and-basil-beef-kebabs/#axzz29jTSubMo", "title":"Lime and Basil Beef Kebabs"},
|
||||
{"url":"http://www.marksdailyapple.com/taco-bowl-with-crispy-kale-chips/#axzz29jTSubMo", "title":"Taco Bowl with Crispy Kale Chips"},
|
||||
{"url":"http://www.marksdailyapple.com/grilled-eggs-with-mexican-chorizo/#axzz29jTSubMo", "title":"Grilled Eggs with Mexican Chorizo"},
|
||||
{"url":"http://www.marksdailyapple.com/banh-mi-salad/#axzz29jTSubMo", "title":"Banh Mi Salad"},
|
||||
{"url":"http://www.marksdailyapple.com/tender-lemon-parsley-brisket/#axzz29jTSubMo", "title":"Tender Lemon-Parsley Brisket"},
|
||||
{"url":"http://www.marksdailyapple.com/butter-stuffed-chicken-kiev/#axzz29jTSubMo", "title":"Butter-Stuffed Chicken Kiev"},
|
||||
{"url":"http://www.marksdailyapple.com/primal-chicken-tikka-masala/#axzz29jTSubMo", "title":"Primal Chicken Tikka Masala"},
|
||||
{"url":"http://www.nerdfitness.com/blog/2012/02/21/how-to-cook-paleo-spaghetti/", "title":"Paleo Spaghetti"},
|
||||
{"url":"http://www.nerdfitness.com/blog/2011/02/21/a-decent-meal/", "title":"How to Grow Up And Cook a Decent Meal"},
|
||||
{"url":"http://www.marksdailyapple.com/fajita-frittata-with-avocado-salsa/#axzz29jTSubMo", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
{"url":"", "title":""},
|
||||
]}
|
74
savetodisk.js
Normal file
74
savetodisk.js
Normal file
@ -0,0 +1,74 @@
|
||||
// Example use of simplecrawler, courtesy of @breck7! Thanks mate. :)
|
||||
|
||||
/**
|
||||
* @param String. Domain to download.
|
||||
* @Param Function. Callback when crawl is complete.
|
||||
*/
|
||||
var downloadSite = function(domain, callback) {
|
||||
var fs = require("node-fs"),
|
||||
url = require("url"),
|
||||
path = require("path"),
|
||||
Crawler = require("simplecrawler").Crawler;
|
||||
|
||||
var myCrawler = new Crawler(domain);
|
||||
myCrawler.interval = 250;
|
||||
myCrawler.maxConcurrency = 5;
|
||||
myCrawler.maxDepth = 1;
|
||||
|
||||
myCrawler.on("fetchcomplete", function(queueItem, responseBuffer, response) {
|
||||
|
||||
// Parse url
|
||||
var parsed = url.parse(queueItem.url);
|
||||
|
||||
// Rename / to index.html
|
||||
if (parsed.pathname === "/") {
|
||||
parsed.pathname = "/index.html";
|
||||
}
|
||||
|
||||
// Where to save downloaded data
|
||||
var outputDirectory = path.join(__dirname, domain);
|
||||
|
||||
// Get directory name in order to create any nested dirs
|
||||
var dirname = outputDirectory + parsed.pathname.replace(/\/[^\/]+$/, "");
|
||||
|
||||
// Path to save file
|
||||
var filepath = 'snapshots/' + outputDirectory + parsed.pathname;
|
||||
|
||||
// Check if DIR exists
|
||||
fs.exists(dirname, function(exists) {
|
||||
|
||||
// If DIR exists, write file
|
||||
if (exists) {
|
||||
fs.writeFile(filepath, responseBuffer, function() {});
|
||||
} else {
|
||||
// Else, recursively create dir using node-fs, then write file
|
||||
fs.mkdir(dirname, 0755, true, function() {
|
||||
fs.writeFile(filepath, responseBuffer, function() {});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
console.log("I just received %s (%d bytes)", queueItem.url, responseBuffer.length);
|
||||
console.log("It was a resource of type %s", response.headers["content-type"]);
|
||||
|
||||
});
|
||||
|
||||
// Fire callback
|
||||
myCrawler.on("complete", function() {
|
||||
callback();
|
||||
});
|
||||
|
||||
// Start Crawl
|
||||
myCrawler.start();
|
||||
|
||||
};
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.log("Usage: node savetodisk.js mysite.com");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
downloadSite(process.argv[2], function() {
|
||||
console.log("Done!");
|
||||
});
|
52
snapshot.js
Normal file
52
snapshot.js
Normal file
@ -0,0 +1,52 @@
|
||||
var Crawler = require("simplecrawler"),fs = require('fs');
|
||||
|
||||
|
||||
//var myCrawler = new Crawler("http://www.bbc.co.uk/food/recipes/chicken_piperade_with_23608");
|
||||
|
||||
var myCrawler = new Crawler("www.bbc.co.uk", "/food/recipes/chicken_piperade_with_23608", 80);
|
||||
|
||||
var htmlfile = __dirname + '/' + 'test.html';
|
||||
|
||||
myCrawler.maxDepth = 1;
|
||||
//myCrawler.interval = 10000; // Ten seconds
|
||||
myCrawler.maxConcurrency = 1;
|
||||
|
||||
|
||||
myCrawler.on('crawlstart', function() {
|
||||
console.log('Crawling started...');
|
||||
});
|
||||
|
||||
myCrawler.on('fetchstart ', function(a, b) {
|
||||
console.log('fetchstart ...');
|
||||
console.log(a);
|
||||
console.log(b);
|
||||
});
|
||||
|
||||
myCrawler.on('fetcherror ', function(a, b) {
|
||||
console.log('Crawling error...');
|
||||
console.log(a);
|
||||
console.log(b);
|
||||
});
|
||||
|
||||
myCrawler.on('fetchclienterror ', function(a, b) {
|
||||
console.log('fetchclienterror error...');
|
||||
console.log(a);
|
||||
console.log(b);
|
||||
});
|
||||
|
||||
myCrawler.on('queueadd ', function(a) {
|
||||
console.log('fetchclienterror error...');
|
||||
console.log(a);
|
||||
|
||||
});
|
||||
|
||||
myCrawler.on("fetchcomplete", function(queueItem, responseBuffer, response) {
|
||||
console.log("I just received %s (%d bytes)", queueItem.url, responseBuffer.length);
|
||||
console.log("It was a resource of type %s", response.headers['content-type']);
|
||||
|
||||
// Do something with the data in responseBuffer
|
||||
|
||||
fs.writeFileSync(htmlfile, responseBuffer);
|
||||
});
|
||||
|
||||
myCrawler.start();
|
@ -7,6 +7,9 @@
|
||||
|
||||
<% include ../partials/weather %>
|
||||
<% include ../partials/trains %>
|
||||
<% include ../partials/calendar %>
|
||||
<% include ../partials/history %>
|
||||
<% include ../partials/tv %>
|
||||
|
||||
</div>
|
||||
|
||||
|
13
views/partials/calendar.ejs
Normal file
13
views/partials/calendar.ejs
Normal file
@ -0,0 +1,13 @@
|
||||
<% if (data.cal.entries.length > 0 ) {%>
|
||||
<div id="container" class="mui-panel">
|
||||
<h2>Calendar</h2>
|
||||
<%
|
||||
for (var i = 0; i < data.cal.entries.length; i++) { %>
|
||||
|
||||
<div class="mui-row"><div class="mui-col-md-12"><%- data.cal.entries[i].combined %></div></div>
|
||||
|
||||
<% } %>
|
||||
|
||||
</div>
|
||||
|
||||
<% } %>
|
@ -59,6 +59,7 @@
|
||||
}
|
||||
</style>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/zepto/1.1.4/zepto.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="libs/microevent.js"></script></head>
|
||||
|
||||
<body>
|
||||
|
14
views/partials/history.ejs
Normal file
14
views/partials/history.ejs
Normal file
@ -0,0 +1,14 @@
|
||||
<% if (data.history.length > 0 ) {%>
|
||||
<div id="container" class="mui-panel">
|
||||
<h2>Today in history</h2>
|
||||
<div class="mui-row"><div class="mui-col-md-12">
|
||||
<%
|
||||
for (var i = 0; i < data.history.length; i++) { %>
|
||||
|
||||
<p><%- data.history[i] %></p>
|
||||
|
||||
<% } %>
|
||||
</div></div>
|
||||
</div>
|
||||
|
||||
<% } %>
|
@ -1,6 +1,6 @@
|
||||
<% if (data.trains.data.length > 0 ) {%>
|
||||
<div id="container" class="mui-panel">
|
||||
|
||||
<h2>Travel</h2>
|
||||
<%
|
||||
for (var i = 0; i < data.trains.data.length; i++) { %>
|
||||
|
||||
|
13
views/partials/tv.ejs
Normal file
13
views/partials/tv.ejs
Normal file
@ -0,0 +1,13 @@
|
||||
<% if (data.tv.entries.length > 0 ) {%>
|
||||
<div id="container" class="mui-panel">
|
||||
<h2>TV</h2>
|
||||
<%
|
||||
for (var i = 0; i < data.tv.entries.length; i++) { %>
|
||||
|
||||
<div class="mui-row"><div class="mui-col-md-12"><%- data.tv.entries[i].combined %></div></div>
|
||||
|
||||
<% } %>
|
||||
|
||||
</div>
|
||||
|
||||
<% } %>
|
@ -1,22 +1,26 @@
|
||||
|
||||
|
||||
<div id="container" class="mui-panel">
|
||||
<h1>Weather</h1>
|
||||
<div class="mui-row"><div class="mui-col-md-12">Currently: <%=data.weather.currently%></div></div>
|
||||
<div class="mui-row"><div class="mui-col-md-12">Later: <%=data.weather.today%></div></div>
|
||||
<h2>Weather</h2>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-12">Currently: <%= data.weather.currently %></div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-12">Today: <%= data.weather.today %></div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-12">Later: <%= data.weather.later %></div>
|
||||
</div>
|
||||
|
||||
<% if (data.weather.alerts.length > 0) {
|
||||
for (var i =0; i < data.weather.alerts.length; i++) {
|
||||
%>
|
||||
<% if (data.weather.alerts.length > 0) {
|
||||
for (var i = 0; i < data.weather.alerts.length; i++) {
|
||||
%>
|
||||
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-12 mui--text-danger"><%=data.weather.alerts[i].title%></div>
|
||||
<div class="mui-col-md-12"><%=data.weather.alerts[i].description%></div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-12 mui--text-danger"><%= data.weather.alerts[i].title %></div>
|
||||
<div class="mui-col-md-12"><%= data.weather.alerts[i].description %></div>
|
||||
</div>
|
||||
|
||||
<%
|
||||
|
||||
}
|
||||
}%>
|
||||
<%
|
||||
}
|
||||
} %>
|
||||
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user