diff --git a/app/js/modules/train.js b/app/js/modules/train.js
index b585bed..14cd5d5 100644
--- a/app/js/modules/train.js
+++ b/app/js/modules/train.js
@@ -131,6 +131,7 @@ let TrainView = Backbone.View.extend({
Platform |
`;
+ let services = [];
if (typeof route.trainServices === 'object' && route.trainServices !== null) {
for (let item of route.trainServices) {
let dest = item.destination[0];
@@ -139,6 +140,7 @@ let TrainView = Backbone.View.extend({
let time = item.sta !== null ? item.sta : `D ${item.std}`;
let status = item.eta !== null ? item.eta : item.etd;
+ services.push({location:dest.locationName, time:time,status:status,platform:platform, cancel:item.cancelReason, type:'train'});
if (!item.isCancelled) {
ws = ws + `
${dest.locationName} ${via} |
@@ -164,7 +166,7 @@ let TrainView = Backbone.View.extend({
let platform = item.platform !== null ? item.platform : '';
let time = item.sta !== null ? item.sta : `D ${item.std}`;
let status = item.eta !== null ? item.eta : item.etd;
-
+ services.push({location:dest.locationName, time:time,status:status,platform:platform, cancel:item.cancelReason, type:'bus'});
// ws = ws + `${dest.locationName} Bus ${via}
`;
// ws = ws + '';
ws = ws + `
diff --git a/app/live/js/app.js b/app/live/js/app.js
index 7f4083a..2fab2df 100644
--- a/app/live/js/app.js
+++ b/app/live/js/app.js
@@ -1 +1 @@
-"use strict";var BitcoinModel,Bitcoin,FxModel,FxView,_typeof,TrainModel,TrainView,WeatherModel,Weather,WeatherSlim,PasswordView,popitout,popitoutSmall,EventModel=Backbone.Model.extend({initialize:function(){this.update()},getDays:function(t,e){var i=void 0,n=void 0;return i=t.getTime(),n=e.getTime(),(n-i)/864e5},update:function(){var t,e=new Date,i=36e5-e.getTime()%36e5,n={};n.days=Math.ceil(this.getDays(e,this.get("event"))),n.weeks=Math.ceil(this.getDays(e,this.get("event"))/7),this.set("data",n),t=function(){this.update()},setTimeout(t.bind(this),i+10)}}),EventView=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.id="e_"+Math.random().toString(36).substr(2,9),this.$events=$("#events"),this.$myEvent=null,this.$el=this.$events,this.initView(),this.render()},render:function(){var t=this.model.get("label"),e=this.model.get("data"),i=t+" "+e.days+" days / "+e.weeks+" weeks";this.$myEvent.empty().append(i)},initView:function(){var t="';this.$html=$(t),this.$events.append(this.$html),this.$myEvent=$("#"+this.id)}});BitcoinModel=Backbone.Model.extend({initialize:function(){this.set("url","/btc");var t={lastGBP:0,lastUSD:0,lows:{gbp:0,usd:0},highs:{gbp:0,usd:0},eclass:""};this.set("btcdata",t),this.update()},update:function(){var t,e,i;this.getBTC(),t=new Date,e=6e4-t.getTime()%6e4,i=function(){this.update()},setTimeout(i.bind(this),e+10)},recalc:function(){var t=this.get("btcdata"),e=t.lastGBP,i=void 0,n=t.gbp,a=t.usd,s=t.lows,o=t.highs,r=t.eclass;0!==t.lastGBP?r=n>e?"up":"down":(s.gbp=n,s.usd=a,o.gbp=n,o.usd=a),e=n,i=a,n"+k.locationName+" TO "+k.filterLocationName+'\n \n Destination | \n Time | \n Status | \n Platform |
\n ',"object"===_typeof(k.trainServices)&&null!==k.trainServices){e=!0,i=!1,n=void 0;try{for(a=k.trainServices[Symbol.iterator]();!(e=(s=a.next()).done);e=!0)o=s.value,r=o.destination[0],l=null!==r.via?""+r.via+"":"",d=null!==o.platform?o.platform:"💠",h=null!==o.sta?o.sta:"D "+o.std,u=null!==o.eta?o.eta:o.etd,t=o.isCancelled?t+"\n "+r.locationName+" "+l+" | \n "+h+' | \n ❌ '+o.cancelReason+" | \n \n
":t+"\n "+r.locationName+" "+l+" | \n "+h+" | \n "+u+" | \n "+d+" | \n
"}catch(t){i=!0,n=t}finally{try{!e&&a.return&&a.return()}finally{if(i)throw n}}}if("object"===_typeof(k.busServices)&&null!==k.busServices){c=!0,m=!1,p=void 0;try{for(g=k.busServices[Symbol.iterator]();!(c=(f=g.next()).done);c=!0)b=f.value,v=b.destination[0],w=null!==v.via?""+v.via+"":"",y=null!==b.platform?b.platform:"",T=null!==b.sta?b.sta:"D "+b.std,$=null!==b.eta?b.eta:b.etd,t=t+"\n 🚌 "+v.locationName+" "+w+" | \n "+T+" | \n "+$+" | \n "+y+" | \n
"}catch(t){m=!0,p=t}finally{try{!c&&g.return&&g.return()}finally{if(m)throw p}}}t+="
",this.$traintext.empty().html(t),this.$traintext.removeClass("mui--hide").addClass("mui--show")}else this.$traintext.removeClass("mui--show").addClass("mui--hide")},initView:function(){var t,e=this,i=this.model.get("target"),n=""+i.toUpperCase()+':
';this.$html=$(n),this.$html.on("click",function(){e.model.getRoute()}),this.$trains.append(this.$html),this.$button=$("#"+i),t="click #$(target)",this.events[t]="showTrains"},showTrains:function(){}}),WeatherModel=Backbone.Model.extend({initialize:function(){var t=this.get("geo");this.set("url","https://api.darksky.net/forecast/9ad2a41d420f3cf4960571bb886f710c/"+t.coords.latitude.toString()+","+t.coords.longitude.toString()+"?units=uk2&exclude=minutely,hourly,alerts,flags"),this.update()},update:function(){var t,e,i;this.getWeather(),t=new Date,e=18e5-t.getTime()%18e5,i=function(){this.update()},setTimeout(i.bind(this),e+10)},getWeather:function(){var t=this;$.ajax({type:"GET",url:t.get("url"),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 i={temperature:e.currently.temperature,icon:e.currently.icon,summary:e.currently.summary,daily:e.daily.summary};t.set(i)},error:function(t,e){}})}}),Weather=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.$weatherText=$("#weatherDescription"),this.$weatherTemp=$("#temp"),this.$weatherIcon=$("#weatherIcon")},render:function(){var t='';this.$weatherTemp.empty().html(parseInt(this.model.get("temperature"))+"°c "),this.$weatherText.empty().html(this.model.get("summary")),this.$weatherIcon.empty().html(t)}}),WeatherSlim=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.$weather=$("#weather"),this.render()},render:function(){var t=this.model.get("summary"),e=this.model.get("temperature"),i=this.model.get("daily"),n=t+" "+e+"° "+i+"";this.$weather.empty().html(n)}}),Array.prototype.random=function(){return this[Math.floor(Math.random()*this.length)]},PasswordView=Backbone.View.extend({el:$("#passwords"),initialize:function(){this.alpha=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"],this.whitespace=[".","~","#","!","$","+","-","+"],this.numbers=["0","1","2","3","4","5","6","7","8","9"],this.left=["Alabama","Alaska","Arizona","Maryland","Nevada","Mexico","Texas","Utah","Glasgow","Inverness","Edinburgh","Dumbarton","Balloch","Renton","Cardross","Dundee","Paisley","Hamilton","Greenock","Falkirk","Irvine","Renfrew","Erskine","London","Hammersmith","Islington","Silver","Black","Yellow","Purple","White","Pink","Red","Orange","Brown","Green","Blue","Amber","Aqua","Azure","Bronze","Coral","Copper","Crimson","Cyan","Ginger","Gold","Indigo","Jade"],this.right=["Aganju","Cygni","Akeron","Antares","Aragoth","Ardus","Carpenter","Cooper","Dahin","Capella","Endriago","Gallina","Fenris","Freya","Glenn","Grissom","Jotunheim","Kailaasa","Lagarto","Muspelheim","Nifleheim","Primus","Vega","Ragnarok","Shepard","Slayton","Tarsis","Mercury","Venus","Mars","Earth","Terra","Jupiter","Saturn","Uranus","Neptune","Pluto","Europa","Ganymede","Callisto","Titan","Juno","Eridanus","Scorpius","Crux","Cancer","Taurus","Lyra","Andromeda","Virgo","Aquarius","Cygnus","Corvus","Taurus","Draco","Perseus","Pegasus","Gemini","Columbia","Bootes","Orion","Deneb","Merope","Agate","Amber","Beryl","Calcite","Citrine","Coral","Diamond","Emerald","Garnet","Jade","Lapis","Moonstone","Obsidian","Onyx","Opal","Pearl","Quartz","Ruby","Sapphire","Topaz","Iron","Lead","Nickel","Copper","Zinc","Tin","Manes","Argon","Neon","Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliett","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whisky","Xray","Yankee","Zulu"],_.bindAll(this,"newClick")},events:{"click #newPassword":"newClick"},numberCluster:function(){return this.numbers.random()+this.numbers.random()+this.numbers.random()},randomAmount:function(t){var e,i="";for(e=0;eLong: "+e+"Short: "+i+"
";t.empty().append(n).removeClass("mui--hide")}}),function(){document.title="Slack"}(),popitout=function(t){var e=window.open(t,"name","height=600,width=570");return window.focus&&e.focus(),!1},popitoutSmall=function(t){var e=window.open(t,"name","height=400,width=520");return window.focus&&e.focus(),!1};
\ No newline at end of file
+"use strict";var BitcoinModel,Bitcoin,FxModel,FxView,_typeof,TrainModel,TrainView,WeatherModel,Weather,WeatherSlim,PasswordView,popitout,popitoutSmall,EventModel=Backbone.Model.extend({initialize:function(){this.update()},getDays:function(t,e){var i=void 0,n=void 0;return i=t.getTime(),n=e.getTime(),(n-i)/864e5},update:function(){var t,e=new Date,i=36e5-e.getTime()%36e5,n={};n.days=Math.ceil(this.getDays(e,this.get("event"))),n.weeks=Math.ceil(this.getDays(e,this.get("event"))/7),this.set("data",n),t=function(){this.update()},setTimeout(t.bind(this),i+10)}}),EventView=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.id="e_"+Math.random().toString(36).substr(2,9),this.$events=$("#events"),this.$myEvent=null,this.$el=this.$events,this.initView(),this.render()},render:function(){var t=this.model.get("label"),e=this.model.get("data"),i=t+" "+e.days+" days / "+e.weeks+" weeks";this.$myEvent.empty().append(i)},initView:function(){var t="';this.$html=$(t),this.$events.append(this.$html),this.$myEvent=$("#"+this.id)}});BitcoinModel=Backbone.Model.extend({initialize:function(){this.set("url","/btc");var t={lastGBP:0,lastUSD:0,lows:{gbp:0,usd:0},highs:{gbp:0,usd:0},eclass:""};this.set("btcdata",t),this.update()},update:function(){var t,e,i;this.getBTC(),t=new Date,e=6e4-t.getTime()%6e4,i=function(){this.update()},setTimeout(i.bind(this),e+10)},recalc:function(){var t=this.get("btcdata"),e=t.lastGBP,i=void 0,n=t.gbp,a=t.usd,s=t.lows,o=t.highs,r=t.eclass;0!==t.lastGBP?r=n>e?"up":"down":(s.gbp=n,s.usd=a,o.gbp=n,o.usd=a),e=n,i=a,n"+E.locationName+" TO "+E.filterLocationName+'\n \n Destination | \n Time | \n Status | \n Platform |
\n ',e=[],"object"===_typeof(E.trainServices)&&null!==E.trainServices){i=!0,n=!1,a=void 0;try{for(s=E.trainServices[Symbol.iterator]();!(i=(o=s.next()).done);i=!0)r=o.value,l=r.destination[0],d=null!==l.via?""+l.via+"":"",h=null!==r.platform?r.platform:"💠",u=null!==r.sta?r.sta:"D "+r.std,c=null!==r.eta?r.eta:r.etd,e.push({location:l.locationName,time:u,status:c,platform:h,cancel:r.cancelReason,type:"train"}),t=r.isCancelled?t+"\n "+l.locationName+" "+d+" | \n "+u+' | \n ❌ '+r.cancelReason+" | \n \n
":t+"\n "+l.locationName+" "+d+" | \n "+u+" | \n "+c+" | \n "+h+" | \n
"}catch(t){n=!0,a=t}finally{try{!i&&s.return&&s.return()}finally{if(n)throw a}}}if("object"===_typeof(E.busServices)&&null!==E.busServices){m=!0,p=!1,g=void 0;try{for(f=E.busServices[Symbol.iterator]();!(m=(b=f.next()).done);m=!0)w=b.value,y=w.destination[0],v=null!==y.via?""+y.via+"":"",T=null!==w.platform?w.platform:"",$=null!==w.sta?w.sta:"D "+w.std,C=null!==w.eta?w.eta:w.etd,e.push({location:y.locationName,time:$,status:C,platform:T,cancel:w.cancelReason,type:"bus"}),t=t+"\n 🚌 "+y.locationName+" "+v+" | \n "+$+" | \n "+C+" | \n "+T+" | \n
"}catch(t){p=!0,g=t}finally{try{!m&&f.return&&f.return()}finally{if(p)throw g}}}t+="
",this.$traintext.empty().html(t),this.$traintext.removeClass("mui--hide").addClass("mui--show")}else this.$traintext.removeClass("mui--show").addClass("mui--hide")},initView:function(){var t,e=this,i=this.model.get("target"),n=""+i.toUpperCase()+':
';this.$html=$(n),this.$html.on("click",function(){e.model.getRoute()}),this.$trains.append(this.$html),this.$button=$("#"+i),t="click #$(target)",this.events[t]="showTrains"},showTrains:function(){}}),WeatherModel=Backbone.Model.extend({initialize:function(){var t=this.get("geo");this.set("url","https://api.darksky.net/forecast/9ad2a41d420f3cf4960571bb886f710c/"+t.coords.latitude.toString()+","+t.coords.longitude.toString()+"?units=uk2&exclude=minutely,hourly,alerts,flags"),this.update()},update:function(){var t,e,i;this.getWeather(),t=new Date,e=18e5-t.getTime()%18e5,i=function(){this.update()},setTimeout(i.bind(this),e+10)},getWeather:function(){var t=this;$.ajax({type:"GET",url:t.get("url"),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 i={temperature:e.currently.temperature,icon:e.currently.icon,summary:e.currently.summary,daily:e.daily.summary};t.set(i)},error:function(t,e){}})}}),Weather=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.$weatherText=$("#weatherDescription"),this.$weatherTemp=$("#temp"),this.$weatherIcon=$("#weatherIcon")},render:function(){var t='';this.$weatherTemp.empty().html(parseInt(this.model.get("temperature"))+"°c "),this.$weatherText.empty().html(this.model.get("summary")),this.$weatherIcon.empty().html(t)}}),WeatherSlim=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.$weather=$("#weather"),this.render()},render:function(){var t=this.model.get("summary"),e=this.model.get("temperature"),i=this.model.get("daily"),n=t+" "+e+"° "+i+"";this.$weather.empty().html(n)}}),_.templateSettings={interpolate:/\{\{(.+?)\}\}/g},Array.prototype.random=function(){return this[Math.floor(Math.random()*this.length)]},PasswordView=Backbone.View.extend({el:"#passwords",passwordTemplate:_.template($("#password-template").html()),initialize:function(){this.alpha=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"],this.whitespace=[".","~","#","!","$","+","-","+"],this.numbers=["0","1","2","3","4","5","6","7","8","9"],this.left=["Alabama","Alaska","Arizona","Maryland","Nevada","Mexico","Texas","Utah","Glasgow","Inverness","Edinburgh","Dumbarton","Balloch","Renton","Cardross","Dundee","Paisley","Hamilton","Greenock","Falkirk","Irvine","Renfrew","Erskine","London","Hammersmith","Islington","Silver","Black","Yellow","Purple","White","Pink","Red","Orange","Brown","Green","Blue","Amber","Aqua","Azure","Bronze","Coral","Copper","Crimson","Cyan","Ginger","Gold","Indigo","Jade"],this.right=["Aganju","Cygni","Akeron","Antares","Aragoth","Ardus","Carpenter","Cooper","Dahin","Capella","Endriago","Gallina","Fenris","Freya","Glenn","Grissom","Jotunheim","Kailaasa","Lagarto","Muspelheim","Nifleheim","Primus","Vega","Ragnarok","Shepard","Slayton","Tarsis","Mercury","Venus","Mars","Earth","Terra","Jupiter","Saturn","Uranus","Neptune","Pluto","Europa","Ganymede","Callisto","Titan","Juno","Eridanus","Scorpius","Crux","Cancer","Taurus","Lyra","Andromeda","Virgo","Aquarius","Cygnus","Corvus","Taurus","Draco","Perseus","Pegasus","Gemini","Columbia","Bootes","Orion","Deneb","Merope","Agate","Amber","Beryl","Calcite","Citrine","Coral","Diamond","Emerald","Garnet","Jade","Lapis","Moonstone","Obsidian","Onyx","Opal","Pearl","Quartz","Ruby","Sapphire","Topaz","Iron","Lead","Nickel","Copper","Zinc","Tin","Manes","Argon","Neon","Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliett","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whisky","Xray","Yankee","Zulu"],this.passwordOut=this.$("#passwordOut"),_.bindAll(this,"newClick")},events:{"click #newPassword":"newClick"},numberCluster:function(){return this.numbers.random()+this.numbers.random()+this.numbers.random()},randomAmount:function(t){var e,i="";for(e=0;e 3 && d < 21) {return 'th';} // Thanks kennebec
+ // if (d % 10 === 1) {return 'st';} else if (d % 10 === 2) {return 'nd';} else if (d % 10 === 3) {return 'rd';} else {return 'th';}
+ const n = d;
+ return Math.floor(n / 10) === 1 ? 'th' : (n % 10 === 1 ? 'st' : (n % 10 === 2 ? 'nd' : (n % 10 === 3 ? 'rd' : 'th')));
+}
+
+function dayNumber() {
+ const now = new Date();
+ const start = new Date(now.getFullYear(), 0, 0);
+ const diff = now - start;
+ const oneDay = 1000 * 60 * 60 * 24;
+ return Math.floor(diff / oneDay);
+}
+
+function breakDay() {
+ const now = new Date();
+ return {
+ year: now.getFullYear(),
+ month: parseInt(now.getMonth()) + 1,
+ day: now.getDate()
+ };
+}
+
+function reduceTrains(d) {
+
+ const titles = [], ta = [];
+ // console.log('reducetrains',d);
+ /*for (let items in d) {
+ if (typeof d[items].title !== 'undefined') {
+ const hash = d[items].title.hashCode();
+ if (titles.indexOf(hash) === -1) {
+ titles.push(hash);
+ ta.push(d[items]);
+ }
+
+ }
+
+ }*/
+
+ for (let item in d) {
+ if (typeof item.title !== 'undefined') {
+ const hash = item.title.hashCode();
+ if (titles.indexOf(hash) === -1) {
+ titles.push(hash);
+ ta.push(item);
+ }
+ }
+ }
+ return ta;
+}
+
+/**
+ * @return {number}
+ */
+function DayDiff(CurrentDate) {
+ const TYear = CurrentDate.getFullYear();
+ const TDay = new Date('January, 01, ' + (parseInt(TYear) + 1));
+ TDay.getFullYear(TYear);
+ let DayCount = (TDay - CurrentDate) / (1000 * 60 * 60 * 24);
+ DayCount = Math.round(DayCount);
+
+ const d = new Date();
+ DayCount = d.daysSince('beginning of this year');
+ return (DayCount);
+}
+
+Array.prototype.indexOfOld = Array.prototype.indexOf;
+Array.prototype.indexOf = function (e, fn) {
+ if (!fn) {
+ return this.indexOfOld(e);
+ } else {
+ if (typeof fn === 'string') {
+ const att = fn;
+ fn = function (e) {
+ return e[att];
+ };
+ }
+ return this.map(fn).indexOfOld(e);
+ }
+};
+
+module.exports = {
+ setEmitter: function (newEmitter) {
+ console.log('Setting events', newEmitter);
+ eventEmitter = newEmitter;
+ },
+ getClock: function (req, res) {
+ // Console.log(todayCache);
+ res.render('pages/clock', todayCache);
+ },
+ getToday: function (req, res) {
+ logger.info(todayCache);
+ res.render('pages/today', todayCache);
+ },
+ getData: function (req, res) {
+ res.setHeader('Content-Type', 'application/json');
+ res.end(JSON.stringify(todayCache));
+ },
+ getTodayDate: function () {
+ let s;
+ const d = new Date();
+ let nextYear = (parseInt(d.getFullYear()) + 1).toString() + '-01-01';
+
+ console.log(d.daysUntil('beginning of next year'));
+ const daysSinceStart = d.daysSince('beginning of this year');
+ const daysRemaining = d.daysUntil('beginning of next year');
+
+ todayCache.data.history = [];
+ s = '' + d.format('{Weekday} {Month} {dd}, {yyyy}') + ' - ';
+
+ /*
+ s = s + 'The ' + daysSinceStart + nth(daysSinceStart) + ' day of ' + dateFormat(
+ d,
+ 'yyyy') + ', and there are ' + daysRemaining + ' days left until the end of the year.';
+ */
+
+ s = s + `The ${daysSinceStart + nth(daysSinceStart)} day of ${dateFormat(d, 'yyyy')}, and there are ${daysRemaining} days until the end of the year`
+
+ logger.debug(s);
+ todayCache.data.today = s;
+ },
+ refreshTrain: function () {
+
+ trains.updateTrains()
+ .then((d) => {
+ 'use strict';
+
+ d = reduceTrains(d);
+
+ eventEmitter.emit('sendSocket', {id: 'trains', data: d});
+ todayCache.data.trains.data = d;
+ todayCache.data.trains.last = new Date();
+ })
+ .catch((e) => {
+ 'use strict';
+ logger.error(e);
+ });
+
+
+ },
+ refreshWeather: function () {
+ weather.newDoGetWeather()
+ .then((d) => {
+ todayCache.data.weather = d;
+ logger.info('Updating weather');
+ broadcastWeather();
+ }).catch((e) => {
+ logger.error(e);
+ });
+
+ },
+
+ refreshTrainAndWeather: function () {
+ this.refreshTrain();
+ this.refreshWeather();
+ },
+ preLoadToday: function () {
+ module.exports.getTodayDate();
+ todayCache.data.cal = {today: [], tomorrow: [], week: []};
+ weather.newDoGetWeather()
+ .then((d) => {
+ todayCache.data.weather = d;
+ })
+ .catch((e) => {
+ logger.error(e);
+ });
+ trains.updateTrains()
+ .then((d) => {
+ 'use strict';
+ console.log('Trains: ', d);
+ todayCache.data.trains.data = d;
+ todayCache.data.trains.last = new Date();
+ })
+ .catch((e) => {
+ 'use strict';
+ console.error(e);
+ });
+ history.updateHistory()
+ .then((d) => {
+ 'use strict';
+ console.log('History result: ', d);
+ todayCache.data.history = d;
+ })
+ .catch((e) => {
+ 'use strict';
+ console.error(e);
+ });
+
+ calHandler.getSimpleCalV3(
+ 'http://www.pogdesign.co.uk/cat/download_ics/60cfdff469d0490545d33d7e3b5c0bcc')
+ .then((d) => {
+ 'use strict';
+ todayCache.data.tv = d;
+ })
+ .catch((e) => {
+ 'use strict';
+ logger.error(e);
+ });
+
+ todayFTSE.getFTSE()
+ .then((d) => {
+ todayCache.data.ftse = d;
+ })
+ .catch((e) => {
+ logger.error(e);
+ });
+
+ quotes.GetQuotes()
+ .then((d) => {
+ todayCache.data.quotes = d;
+ })
+ .catch((e) => {
+ logger.error(e);
+ });
+
+
+ for (let t = 0; t < calHandler.calendars.length; t++) {
+ calHandler.getAdvancedCalV3(calHandler.calendars[t])
+ .then((d) => {
+ 'use strict';
+ todayCache.data.cal.today = todayCache.data.cal.today.concat(d.today);
+ todayCache.data.cal.tomorrow = todayCache.data.cal.tomorrow.concat(d.tomorrow);
+ todayCache.data.cal.week = todayCache.data.cal.week.concat(d.week);
+ })
+ .catch((e) => {
+ 'use strict';
+ logger.error(e);
+ });
+ }
+
+ swedishWord.getSwedishWord()
+ .then((d) => {
+ 'use strict';
+ console.log('Swedish result: ', d);
+ todayCache.data.swedish = d;
+ })
+ .catch((e) => {
+ 'use strict';
+ console.error(e);
+ });
+
+ mdFitbit.getYesterdayFitbit()
+ .then((d) => {
+ todayCache.data.fitbit = d;
+ })
+ .catch((e) => {
+ 'use strict';
+ console.error(e);
+ });
+
+ todayCache.date = breakDay();
+ },
+ preLoadTodayTest: function () {
+ module.exports.getTodayDate();
+ todayCache.data.cal = {today: [], tomorrow: [], week: []};
+
+
+ todayCache.date = breakDay();
+ },
+ broadcast: function () {
+ console.log('BROADCAST');
+ broadcastWeather();
+ eventEmitter.emit('sendSocket', {id: 'trains', data: todayCache.data.trains.data});
+
+ }
+};
+
+setTimeout(function () {
+ loadData();
+ if (runable()) {
+ module.exports.preLoadToday();
+ }
+ //Module.exports.preLoadToday();
+
+}, 5000);
+
+setTimeout(function () {
+ // mdMailer.sendEmailV1(todayCache, __dirname);
+ // saveToDB(todayCache);
+ saveData();
+}, 45000);
+
+setInterval(function () {
+
+ // EventEmitter.emit('sendSocket',{id:'weather',data:todayCache.data.weather});
+ // broadcastWeather();
+ // eventEmitter.emit('sendSocket', {id: 'trains', data: todayCache.data.trains.data});
+
+
+}, (60000));
+
+
+cron.schedule('30 6 * * *', function () {
+ if (runable()) {
+ module.exports.preLoadToday();
+ }
+
+ return -1;
+});
+
+cron.schedule('0 */1 * * *', function () {
+ // Module.exports.refreshTrainAndWeather();
+ // this.refreshTrain();
+ module.exports.refreshWeather();
+
+ return -1;
+});
+
+cron.schedule('*/15 * * * *', function () {
+ module.exports.refreshTrain();
+
+ // Module.exports.refreshWeather();
+
+ return -1;
+});
+
+cron.schedule('45 6 * * *', function () {
+ mdMailer.sendEmailV1(todayCache, __dirname);
+ saveToDB(todayCache);
+ // Console.log('tick');
+ return -1;
+});
+
+
diff --git a/manifest.json b/manifest.json
new file mode 100644
index 0000000..e753fdf
--- /dev/null
+++ b/manifest.json
@@ -0,0 +1,11 @@
+{
+ "name": "Silvrtree Slack",
+ "short_name": "Slack",
+ "start_url": "/slack",
+ "display": "standalone",
+ "background_color" : "#fff",
+ "related_applications": [{
+ "platform": "web"
+ }]
+
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index 7dcad62..5c657cb 100644
--- a/package.json
+++ b/package.json
@@ -41,8 +41,10 @@
"jsonfile": "^2.3.0",
"lodash": "^4.11.2",
"log4js": "^0.6.35",
+ "lowdb": "^0.16.2",
"mammoth": "^1.0.1",
"nano": "^6.2.0",
+ "node-localstorage": "^1.3.0",
"request": "^2.72.0",
"simple-weather": "^1.2.2",
"sugar-date": "^1.5.1",
diff --git a/views/pages/slackV2-min.ejs b/views/pages/slackV2-min.ejs
index 30628b4..c4441d1 100644
--- a/views/pages/slackV2-min.ejs
+++ b/views/pages/slackV2-min.ejs
@@ -376,7 +376,7 @@
w.weather = new WeatherSlim({model: new WeatherModel({geo:show_weather})});
});
- w.contractEnds = new EventView({model:new EventModel({event:new Date(2017, 6, 5), label: 'Contract Ends:'})});
+ w.contractEnds = new EventView({model:new EventModel({event:new Date(2017, 5, 30), label: 'Contract Ends:'})});
w.bitcoin = new Bitcoin({model: new BitcoinModel()});
w.fx = new FxView({model: new FxModel()});
w.dbqglqView = new TrainView({model: new TrainModel({from: 'dbe', to: 'glq'})});
diff --git a/views/pages/slackV2.ejs b/views/pages/slackV2.ejs
index eb87899..ecdca66 100644
--- a/views/pages/slackV2.ejs
+++ b/views/pages/slackV2.ejs
@@ -392,7 +392,7 @@
navigator.geolocation.getCurrentPosition((show_weather) => {
w.weather = new WeatherSlim({model: new WeatherModel({geo:show_weather})});
});
- w.contractEnds = new EventView({model:new EventModel({event:new Date(2017, 6, 5), label: 'Contract Ends:'})});
+ w.contractEnds = new EventView({model:new EventModel({event:new Date(2017, 5, 30), label: 'Contract Ends:'})});
w.bitcoin = new Bitcoin({model: new BitcoinModel()});
w.fx = new FxView({model: new FxModel()});
w.dbqglqView = new TrainView({model: new TrainModel({from: 'dbe', to: 'glq'})});