From d0d5164749097f3f5df7a8f1b8fb354850783603 Mon Sep 17 00:00:00 2001 From: martind2000 Date: Fri, 8 Jan 2016 11:33:24 +0000 Subject: [PATCH] added a page for jessica --- .idea/libraries/silvrgit_node_modules.xml | 14 + app/app.js | 54 ++- app/gfx/information-icon-24.png | Bin 0 -> 1259 bytes app/gfx/information-icon-32.png | Bin 0 -> 1586 bytes app/jessica.html | 89 +++++ app/js/jessica.js | 424 ++++++++++++++++++++++ app/template/trains.ejs | 2 +- lib/train.js | 39 ++ package.json | 9 +- web-server.js | 7 +- 10 files changed, 625 insertions(+), 13 deletions(-) create mode 100644 .idea/libraries/silvrgit_node_modules.xml create mode 100644 app/gfx/information-icon-24.png create mode 100644 app/gfx/information-icon-32.png create mode 100644 app/jessica.html create mode 100644 app/js/jessica.js diff --git a/.idea/libraries/silvrgit_node_modules.xml b/.idea/libraries/silvrgit_node_modules.xml new file mode 100644 index 0000000..c34146e --- /dev/null +++ b/.idea/libraries/silvrgit_node_modules.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/app.js b/app/app.js index 0541bef..5da5c49 100644 --- a/app/app.js +++ b/app/app.js @@ -214,11 +214,46 @@ }); }; + 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) { + console.log(data); + + updateTrain(target,data); + //updateFX(fxdata); + }, + error: function (xhr, type) { + console.log("ajax error"); + console.log(xhr); + console.log(type); + } + }); + + }; + + var getDBEGLQ = function () { - var url = '/dbeglq'; - + // var url = '/dbeglq'; + var url = '/getnexttraintimes?from=dbe&to=glq'; $.ajax({ type: 'GET', url: url, @@ -250,7 +285,8 @@ var getGLQDBE = function () { - var url = '/glqdbe'; + //var url = '/glqdbe'; + var url = '/getnexttraintimes?from=glq&to=dbe'; $.ajax({ type: 'GET', @@ -388,15 +424,19 @@ get_weather(); btcValue(); getFX(); - getDBEGLQ(); - getGLQDBE(); + //getDBEGLQ(); + //getGLQDBE(); + getNextTrainTime('dbe','glq'); + getNextTrainTime('glq','dbe'); // start 15 minute timer _fastTimer = setInterval(function () { btcValue(); - getDBEGLQ(); - getGLQDBE(); + // getDBEGLQ(); + // getGLQDBE(); + getNextTrainTime('dbe','glq'); + getNextTrainTime('glq','dbe'); }, (60000)); _slowTimer = setInterval(function () { diff --git a/app/gfx/information-icon-24.png b/app/gfx/information-icon-24.png new file mode 100644 index 0000000000000000000000000000000000000000..6c05b88cbe21bdd02e7430cc1e8f14cd0330fc91 GIT binary patch literal 1259 zcmV7_LIeA zV^b32oY^0drNRa?8ivF91LA~D0YMxAQTbEpDp+jG-MKHlFRyfEFS)t5=iPh0bH4MP z`-(8b^Lq8AM4Iwwtfi4m;}PGhQ5qdI8faAR&slygm=6r%H~|qqq2&g~n1+ z3?f5yzTTOMP?5Uu2wf!jO9 zT5pYEUDqItj!#a{<`t0%3eIV2Q`3@Wip2aB6OW!f^my^gjUl*s#{uM*%{PW)N?bGx zH-wPkXV&3nAC;y~U~6ReJlVl^$DNRIqe^jX1r8DQ7p zT0a$S$+WWdsTORwavi>I>SD9!MbjG%KU>N(I7NH1gjzn#ejM1;6l^G~fU~aT&m}lS>YFZT=30tgYAbQ~Y zGi?C^-<$t5@Gwg%PX@fpqx$fIA2`_zzqS7@+cX-9@eDYChDVWZj>63ZP<^4D3i($+ z2Bj~pl}&qoYzWAJ05EseW3c~36Km|~75z2kN0DXTY}}EN0L|BKuzj^>0s!95$&w8p z*PIRjcymK0u1qjN+0lB|d2>VnjBo&6v39--PE zrq?klGEzf8VTE08OdmiauK}0oZo%cIWoAe>M^bZjKqbjkJX%uNk?k+b)!O<+6?nW; z%Dc^(R(K)R0;h=k3aWu}4=iyvepAzZ1C5yO! zR)6`rlED*+v9Rm83^qwozxB;=7PWy9&qb1RESYcW`a>dlOUS;;? zb`(7!92<06Mpp&e(vpB8V-yUY?dnrgdhBS?#$4ZB^aovb$aNVe(zC`Gfh#J6sG;cK za^D~f+;wmV5EC&6mc}iFP`wt2Z#Y=r0;fBB)zmzoDTM%fX1uN=4H9I>N3a#~3sFDq zx+VdzrtW^E>|k)rss1SOhJKZtf93Z*@KIIbyO%&5@Os?LeRl}W#!!fu6($3WI>)hh z_@1H`6)oKP`{eusC7bCT$ups;Tum3hx1Gbcz;*v02=@5C0Xs$HK>5 z?v3)n)HM3kQbVJda~=Q;Gdx_vsL|w+ALVb0%jp2;$n86nmHfAb&?>8nHg*T|@h>XN Vm6=@~WQhO(002ovPDHLkV1g`HSls{s literal 0 HcmV?d00001 diff --git a/app/gfx/information-icon-32.png b/app/gfx/information-icon-32.png new file mode 100644 index 0000000000000000000000000000000000000000..28f38d396c32cafef6d10828b2a45ea0bb53637c GIT binary patch literal 1586 zcmV-22F>}2P)b@!;_cL0JS82NysPl`y3+Cv!+m&B{R~!z>3Z$7pJxrazjo(aB~^iPWS~ zlQ7Xz%5llbW!x}vM8OSnLlk9`x3IsZb1(1VTfProo|!ZEym!yN_jk`d_jm3mftRwp z^kM)tvq-0sjwOvG)!DoCr1wZGNRN{KSui`X*_(MKUMw6-O)lwMq$)4*c9QNUT|+>w zJQDy~*pHgkq*oUXCW$6#Z6VfySaZVI~ednje7LN+>MRIrmMg?gxP@{C|Gj?|4 zdV>*VHO;uuC>U)Ah{?{8=mlUu^KzlE2m7foKRz7Mfqq`a``;!LiYxA;zO_^AI3_r9 z!Wlq5H6OZrCx+;dF)k8HnUw#wSgp8PTaRnC4QMc!=(i0zUp1nG2V#6w7*q;5_v=EdzL|*DhsN^zqna$X6;4IGHs_pHU zNu>zz^Wk>0shvm0A>*S$v2w;_DCKgrQ-ZGgs{(qf+#N&_0mzWp8SWw6NG3Zu3NeHI z`Od%n<0Q&&KX4fx5var3jMupR>5c=aY1F&)PmB)dAS4utOLyzA?pP&!1A_Q(yRZZa zWdIhFvCU=j0UCVv(gsMpBU3{_vrRCQ|Cofv@HbC$f<(G*1 z%uX7O1u0{>y_Al?*zQ8lM!_UpJv|m$I^%L8p0&gQVzMG_60L9JMlmnjSm@#GklGh=ZJ-vo* zvO|!FSlP` zl9OK5?}H?EkUugfMA93u2OBH9l{Js)K~j%;dXNw<3?$AU6&i$up&_*E9zPbfjfc4mzh*(nhK*C&}Bgy^HxYB3{H zX~yK?!59+}%!`q;G#XlQnUaki)Aa`pV%XTDG=&!LEinJbcGJ9zHHSDVOHGjVVoPY>^p0mXX kgn_`ge4f*eo4lF#KV*(^A3J}Py#N3J07*qoM6N<$f>d4dV*mgE literal 0 HcmV?d00001 diff --git a/app/jessica.html b/app/jessica.html new file mode 100644 index 0000000..2803579 --- /dev/null +++ b/app/jessica.html @@ -0,0 +1,89 @@ + + + + + + + + Trains + + + + + + + + +
+
+
Trains
+
+
+
+
Paisley > GLC -- : --
+
GLC > Partick -- : --
+
Partick > DBE -- : --
+
GLQ > DBE -- : --
+
+ +
+ +
+
+ + + +
+ + +
+ +
+
+ + + + + + diff --git a/app/js/jessica.js b/app/js/jessica.js new file mode 100644 index 0000000..634539e --- /dev/null +++ b/app/js/jessica.js @@ -0,0 +1,424 @@ +(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: 2015, + m: 4, + d: 10 + }]; + var addDays = function (myDate, days) { + return new Date(myDate.getTime() + days * 24 * 60 * 60 * 1000); + }; + + 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(2015, 4, 10); + 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(), + 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 ' + '' + data.daily.summary + ''); + + }, + 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 url = '/getnexttraintimes?from=' + fromStation + '&to=' + toStation ; + var target = fromStation + toStation; + console.log('Target: ' + target); + $.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(target,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 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); + + // 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(); + // btcValue(); + // getFX(); + //getDBEGLQ(); + //getGLQDBE(); + getNextTrainTime('glc','pyg'); + getNextTrainTime('dbe','glq'); + getNextTrainTime('ptk','glc'); + getNextTrainTime('dbe','ptk'); + + + + // start 15 minute timer + + _fastTimer = setInterval(function () { + //btcValue(); + // getDBEGLQ(); + // getGLQDBE(); + getNextTrainTime('glc','pyg'); + getNextTrainTime('dbe','glq'); + getNextTrainTime('ptk','glc'); + getNextTrainTime('dbe','ptk'); + }, (60000)); + + _slowTimer = setInterval(function () { + + // getFX(); + get_weather(); + }, (60000 * 15)); + + + + $('#glqdbeB').on('click',function(){ + getTrains('glq','dbe'); + }); + + $('#pygglcB').on('click',function(){ + getTrains('pyg','glc'); + }); + + $('#glcptkB').on('click',function(){ + getTrains('glc','ptk'); + }); + + $('#ptkdbeB').on('click',function(){ + getTrains('ptk','dbe'); + }); + + + + + +})(); + +var popitout = function (url) { + 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; +}; diff --git a/app/template/trains.ejs b/app/template/trains.ejs index 4892e33..1c6b2c2 100644 --- a/app/template/trains.ejs +++ b/app/template/trains.ejs @@ -1,4 +1,4 @@ -
To: <%=filterLocationName%>
+
<%=locationName%> TO <%=filterLocationName%>
diff --git a/lib/train.js b/lib/train.js index 149a276..de1a924 100644 --- a/lib/train.js +++ b/lib/train.js @@ -83,6 +83,45 @@ module.exports = { res.end(JSON.stringify({})); } + }, + getNextTrainTimes: function(req, res) { + console.log(req); + console.log('---------'); + console.log(req.query); + var trainFrom, trainTo, trainToken, url; + if (req.query.hasOwnProperty('from') && req.query.hasOwnProperty('from')) { + trainFrom = req.query.from; + trainTo = req.query.to; + trainToken = trainFrom + trainTo; + url = '/next/' + trainFrom + '/to/' + trainTo + '/1?accessToken=215b99fe-b237-4a01-aadc-cf315d6756d8'; + console.log('Requesting latest time for : ' + trainToken); + + var now = new Date(); + var nowSeconds = (now.getHours() * (60 * 60)) + (now.getMinutes() * 60); + console.log('Now Seconds: ' + nowSeconds); + if (trainCache.last[trainToken] == null || nowSeconds != trainCache.last[trainToken]) { + + Query(function (a, b) { + + var ts = a.departures[0].service; + var output = {}; + console.log(ts); + //GLOBAL.lastcheck = now; + console.log(ts.sta); + console.log(toSeconds(ts.sta)); + + output.sta = ts.sta; + output.eta = ts.eta; + trainCache.data[trainToken] = output; + // trainCache.last.glqdbe = toSeconds(ts.sta); + // console.log(ts); + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(trainCache.data[trainToken])); + }, res, 'huxley.apphb.com', url); + + } + } + } }; diff --git a/package.json b/package.json index 11ab6df..c240d07 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,12 @@ "name": "silvrtree", "version": "0.1.1", "devDependencies": { - "mongodb": "*", - "node-rss": "^1.0.1", - "pg": "*" + "htmlparser": "^1.7.7", + "mammoth": "^0.3.25-pre.1", + "wordsoap": "^0.2.0" }, "dependencies": { - "express": "3.x" + "express": "3.x", + "unstyler": "^0.2.2" } } diff --git a/web-server.js b/web-server.js index 9c7a806..d0d3c18 100644 --- a/web-server.js +++ b/web-server.js @@ -1,4 +1,6 @@ -var express = require('express'), path = require('path'), http = require('http'), fx = require('./lib/fx'), btc = require('./lib/btc'), train = require('./lib/train'), password = require('./lib/password') +var express = require('express'), path = require('path'), http = require('http'), + fx = require('./lib/fx'), btc = require('./lib/btc'), train = require('./lib/train'), + password = require('./lib/password'), clean = require('./lib/clean') //train = require('lib/train') /* ,submit = require('./routes/mongo/submit') */ ; @@ -32,9 +34,12 @@ app.configure(function () { app.use('/dbeglq', train.dbe_glq); app.use('/glqdbe', train.glq_dbe); app.use('/gettrains', train.getTrainTimes); + app.use('/getnexttraintimes', train.getNextTrainTimes); app.use('/generate', password.generate); + app.use('/cleanit', clean.cleanit); + app.use('/lot', function (req, res) { var pg = require('pg');
Destination Time