updated work calendar link

This commit is contained in:
Martin Donnelly 2016-02-29 15:05:57 +00:00
parent 62e3c8711e
commit 929904325f
15 changed files with 707 additions and 453 deletions

View File

@ -2,7 +2,7 @@
var lastGBP = 0.0,
lastUSD = 0.0,
_fasttimer, _slowTimer, myBTC =3.49524333;
_fasttimer, _slowTimer, myBTC = 3.49524333;
var lows = {
gbp: 0,
usd: 0
@ -12,7 +12,6 @@
usd: 0
};
var list = [{
title: '101B ends',
y: 2013,
@ -26,6 +25,10 @@
m: 4,
d: 4
}];
MicroEvent.mixin(this);
var self = this;
var addDays = function (myDate, days) {
return new Date(myDate.getTime() + days * 24 * 60 * 60 * 1000);
};
@ -37,10 +40,11 @@
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 end101;
var endContract = new Date();
var third = new Date();
start101.setFullYear(2013, 9, 24);
@ -59,6 +63,11 @@
var get_weather = function () {
navigator.geolocation.getCurrentPosition(show_weather);
};
this.bind('displayWeather', function (data) {
$('#weather').html(data.currently.summary + ' ' + data.currently.temperature + '&deg;c&nbsp;<em>' + data.daily.summary + '</em>');
});
var show_weather = function (position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
@ -78,11 +87,7 @@
},
success: function (data) {
// console.log(data);
var calc = ((5.0 / 9.0 * (data.currently.temperature - 32)));
$('#weather').html(data.currently.summary + " " + parseInt(calc) + '&deg;c&nbsp;' + '<em>' + data.daily.summary + '</em>');
self.trigger('displayWeather', data);
},
error: function (xhr, type) {
console.log("ajax error");
@ -124,20 +129,14 @@
title = "High: $" + parseFloat(highs.usd.toFixed(2)) + " / Low $" + parseFloat(lows.usd.toFixed(2));
elm.html("&#36;" + parseFloat(u.toFixed(2)) + " / &pound;" + parseFloat(g.toFixed(2)) + " (&pound;" + 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));
var elm = $('#fx');
elm.html("&pound;1 = &#36;" + parseFloat(data.gpbe.toFixed(2)) + " = " + parseFloat(data.sekex.toFixed(2)) + " SEK");
// elm.prop('title', title);
};
var btcValue = function () {
var url = '/btc';
@ -171,6 +170,9 @@
});
};
this.bind('getBTC', function () {
btcValue();
});
var getFX = function () {
var url = '/fx';
@ -214,9 +216,8 @@
});
};
var getNextTrainTime = function(toStation,fromStation)
{
var url = '/getnexttraintimes?from=' + fromStation + '&to=' + toStation ;
var getNextTrainTime = function (toStation, fromStation) {
var url = '/getnexttraintimes?from=' + fromStation + '&to=' + toStation;
var target = fromStation + toStation;
$.ajax({
type: 'GET',
@ -231,13 +232,9 @@
'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(target,data);
//updateFX(fxdata);
updateTrain(target, data);
},
error: function (xhr, type) {
console.log("ajax error");
@ -248,86 +245,15 @@
};
var getDBEGLQ = function () {
// var url = '/dbeglq';
var url = '/getnexttraintimes?from=dbe&to=glq';
$.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('dbeglq',data);
//updateFX(fxdata);
},
error: function (xhr, type) {
console.log("ajax error");
console.log(xhr);
console.log(type);
}
});
};
var getGLQDBE = function () {
//var url = '/glqdbe';
var url = '/getnexttraintimes?from=glq&to=dbe';
$.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);
//updateFX(fxdata);
},
error: function (xhr, type) {
console.log("ajax error");
console.log(xhr);
console.log(type);
}
});
};
var updateTrain = function (n, obj) {
var elm = $('#'+n);
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);
};
@ -335,14 +261,12 @@
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 getTrains = function (from, to) {
var url = '/gettrains?from=' + from + "&to=" + to;
$.ajax({
@ -352,8 +276,6 @@
dataType: 'json',
timeout: 10000,
//contentType: ('application/json'),
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
@ -361,9 +283,6 @@
},
success: function (data) {
console.log(data);
// updateTrain('glqdbe',data);
getTrainsCB(data);
},
error: function (xhr, type) {
@ -376,18 +295,14 @@
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 generatePassword = function (from, to) {
var url = '/generate';
$.ajax({
@ -406,8 +321,6 @@
},
success: function (data) {
console.log(data);
formatPassword(data);
},
error: function (xhr, type) {
@ -418,25 +331,19 @@
});
};
tick();
get_weather();
btcValue();
self.trigger('getBTC');
getFX();
//getDBEGLQ();
//getGLQDBE();
getNextTrainTime('dbe','glq');
getNextTrainTime('glq','dbe');
getNextTrainTime('dbe', 'glq');
getNextTrainTime('glq', 'dbe');
// start 15 minute timer
_fastTimer = setInterval(function () {
btcValue();
// getDBEGLQ();
// getGLQDBE();
getNextTrainTime('dbe','glq');
getNextTrainTime('glq','dbe');
self.trigger('getBTC');
getNextTrainTime('dbe', 'glq');
getNextTrainTime('glq', 'dbe');
}, (60000));
_slowTimer = setInterval(function () {
@ -445,22 +352,27 @@
get_weather();
}, (60000 * 15));
$('#dbeglq').on('click',function(){
getTrains('dbe','glq');
$('#dbeglq').on('click', function () {
self.trigger('getTrains', 'dbe', 'glq');
});
$('#glqdbe').on('click',function(){
getTrains('glq','dbe');
$('#glqdbe').on('click', function () {
self.trigger('getTrains', 'glq', 'dbe');
});
$('#newPassword').on('click', function() {
$('#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');
var newwindow = window.open(url, 'name', 'height=600,width=570');
if (window.focus) {
newwindow.focus()
}
@ -468,7 +380,7 @@ var popitout = function (url) {
};
var popitoutSmall = function (url) {
newwindow = window.open(url, 'name', 'height=400,width=520');
var newwindow = window.open(url, 'name', 'height=400,width=520');
if (window.focus) {
newwindow.focus()
}

12
app/app.min.js vendored
View File

@ -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)+"&deg;c&nbsp;<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("&#36;"+parseFloat(r.toFixed(2))+" / &pound;"+parseFloat(e.toFixed(2))+" (&pound;"+parseFloat(l.toFixed(2))+")"),i.prop("title",c)},d=function(e){var o=$("#fx");o.html("&pound;1 = &#36;"+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+"&deg;c&nbsp;<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("&#36;"+parseFloat(a.toFixed(2))+" / &pound;"+parseFloat(b.toFixed(2))+" (&pound;"+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("&pound;1 = &#36;"+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
View 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
View 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;
}

View File

@ -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
View 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
View 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
View 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();

View File

@ -7,6 +7,9 @@
<% include ../partials/weather %>
<% include ../partials/trains %>
<% include ../partials/calendar %>
<% include ../partials/history %>
<% include ../partials/tv %>
</div>

View 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>
<% } %>

View File

@ -59,6 +59,7 @@
}
</style>
<script src="//cdnjs.cloudflare.com/ajax/libs/zepto/1.1.4/zepto.min.js"></script>
</head>
<script src="libs/microevent.js"></script></head>
<body>

View 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>
<% } %>

View File

@ -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
View 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>
<% } %>

View File

@ -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++) {
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 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>