Forecast stuff

This commit is contained in:
Martin Donnelly 2018-04-15 22:55:47 +01:00
parent c2a4961400
commit e9b1e747ab
8 changed files with 297 additions and 12 deletions

216
package-lock.json generated
View File

@ -82,6 +82,14 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.4.6.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-9.4.6.tgz",
"integrity": "sha512-CTUtLb6WqCCgp6P59QintjHWqzf4VL1uPA27bipLAPxFqrtK1gEYllePzTICGqQ8rYsCbpnsNypXjjDzGAAjEQ==" "integrity": "sha512-CTUtLb6WqCCgp6P59QintjHWqzf4VL1uPA27bipLAPxFqrtK1gEYllePzTICGqQ8rYsCbpnsNypXjjDzGAAjEQ=="
}, },
"@types/winston": {
"version": "2.3.9",
"resolved": "https://registry.npmjs.org/@types/winston/-/winston-2.3.9.tgz",
"integrity": "sha512-zzruYOEtNgfS3SBjcij1F6HlH6My5n8WrBNhP3fzaRM22ba70QBC2ATs18jGr88Fy43c0z8vFJv5wJankfxv2A==",
"requires": {
"@types/node": "9.4.6"
}
},
"JSONStream": { "JSONStream": {
"version": "1.3.2", "version": "1.3.2",
"resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.2.tgz", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.2.tgz",
@ -1028,6 +1036,11 @@
} }
} }
}, },
"bson": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/bson/-/bson-1.0.6.tgz",
"integrity": "sha512-D8zmlb46xfuK2gGvKmUjIklQEouN2nQ0LEHHeZ/NoHM2LDiMk2EYzZ5Ntw/Urk+bgMDosOZxaRzXxvhI5TcAVQ=="
},
"buffer": { "buffer": {
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.1.0.tgz", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.1.0.tgz",
@ -1042,6 +1055,11 @@
"resolved": "https://registry.npmjs.org/buffer-more-ints/-/buffer-more-ints-0.0.2.tgz", "resolved": "https://registry.npmjs.org/buffer-more-ints/-/buffer-more-ints-0.0.2.tgz",
"integrity": "sha1-JrOIXRD6E9t/wBquOquHAZngEkw=" "integrity": "sha1-JrOIXRD6E9t/wBquOquHAZngEkw="
}, },
"buffer-shims": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz",
"integrity": "sha1-mXjOMXOIxkmth5MCjDR37wRKi1E="
},
"buffer-xor": { "buffer-xor": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
@ -1910,6 +1928,11 @@
"array-find-index": "1.0.2" "array-find-index": "1.0.2"
} }
}, },
"cycle": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz",
"integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI="
},
"d": { "d": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz", "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz",
@ -1925,6 +1948,26 @@
"integrity": "sha1-7H6lDHhWTNNsnV7Bj2Yyn63ieCk=", "integrity": "sha1-7H6lDHhWTNNsnV7Bj2Yyn63ieCk=",
"dev": true "dev": true
}, },
"dark-sky-api": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/dark-sky-api/-/dark-sky-api-0.6.3.tgz",
"integrity": "sha512-q5EAH72YxLjDXBZd8dxTR+N17xvZ84JBUKDCXb62I472YFqjd2igFhBGNaGXD26rIYMIpCorEhmCLqTX1K20yQ==",
"requires": {
"dark-sky-skeleton": "0.1.45",
"geo-loc-utils": "0.0.2",
"moment": "2.21.0"
}
},
"dark-sky-skeleton": {
"version": "0.1.45",
"resolved": "https://registry.npmjs.org/dark-sky-skeleton/-/dark-sky-skeleton-0.1.45.tgz",
"integrity": "sha512-tLk3sBTbk3eBjPYE0PLW1v8Sa2HYe8cbExkXSaEhPBWeLPh4rGioVeEXeCLxAOyPWl84KIeKI38Cp5YyvNRv9Q==",
"requires": {
"fetch-jsonp": "1.1.3",
"isomorphic-fetch": "2.2.1",
"query-string": "4.3.4"
}
},
"dashdash": { "dashdash": {
"version": "1.14.1", "version": "1.14.1",
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
@ -2351,6 +2394,11 @@
"es6-symbol": "3.1.1" "es6-symbol": "3.1.1"
} }
}, },
"es6-promise": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.2.1.tgz",
"integrity": "sha1-7FYjOGgDKQkgcXDDlEjiREndH8Q="
},
"es6-symbol": { "es6-symbol": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.1.tgz", "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.1.tgz",
@ -2909,6 +2957,11 @@
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
"integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU="
}, },
"eyes": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz",
"integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A="
},
"fancy-log": { "fancy-log": {
"version": "1.3.2", "version": "1.3.2",
"resolved": "https://registry.npmjs.org/fancy-log/-/fancy-log-1.3.2.tgz", "resolved": "https://registry.npmjs.org/fancy-log/-/fancy-log-1.3.2.tgz",
@ -2963,6 +3016,11 @@
"sax": "1.2.4" "sax": "1.2.4"
} }
}, },
"fetch-jsonp": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/fetch-jsonp/-/fetch-jsonp-1.1.3.tgz",
"integrity": "sha1-nrnlhboIqvcAVjU40Xu+u81aPbI="
},
"figures": { "figures": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz",
@ -4202,6 +4260,11 @@
"is-property": "1.0.2" "is-property": "1.0.2"
} }
}, },
"geo-loc-utils": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/geo-loc-utils/-/geo-loc-utils-0.0.2.tgz",
"integrity": "sha1-lgvTsBo0rnVl85RfGewx1JDBghI="
},
"geolocation": { "geolocation": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/geolocation/-/geolocation-0.2.0.tgz", "resolved": "https://registry.npmjs.org/geolocation/-/geolocation-0.2.0.tgz",
@ -6610,6 +6673,53 @@
} }
} }
}, },
"log4js-node-mongodb": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/log4js-node-mongodb/-/log4js-node-mongodb-2.2.1.tgz",
"integrity": "sha1-kKHaEMHg9lzzUfd3eUPokJoE5b8=",
"requires": {
"log4js": "0.6.38",
"lx-helpers": "0.5.1",
"mongodb": "2.2.35"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"log4js": {
"version": "0.6.38",
"resolved": "https://registry.npmjs.org/log4js/-/log4js-0.6.38.tgz",
"integrity": "sha1-LElBFmldb7JUgJQ9P8hy5mKlIv0=",
"requires": {
"readable-stream": "1.0.34",
"semver": "4.3.6"
}
},
"readable-stream": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
"integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=",
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "0.0.1",
"string_decoder": "0.10.31"
}
},
"semver": {
"version": "4.3.6",
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz",
"integrity": "sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto="
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
}
}
},
"loggly": { "loggly": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/loggly/-/loggly-1.1.1.tgz", "resolved": "https://registry.npmjs.org/loggly/-/loggly-1.1.1.tgz",
@ -6816,6 +6926,11 @@
"es5-ext": "0.10.39" "es5-ext": "0.10.39"
} }
}, },
"lx-helpers": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/lx-helpers/-/lx-helpers-0.5.1.tgz",
"integrity": "sha1-fIU70NWlMrYCOZkDeNRAQn5IjCQ="
},
"macaddress": { "macaddress": {
"version": "0.2.8", "version": "0.2.8",
"resolved": "https://registry.npmjs.org/macaddress/-/macaddress-0.2.8.tgz", "resolved": "https://registry.npmjs.org/macaddress/-/macaddress-0.2.8.tgz",
@ -7195,6 +7310,46 @@
"resolved": "https://registry.npmjs.org/moment/-/moment-2.21.0.tgz", "resolved": "https://registry.npmjs.org/moment/-/moment-2.21.0.tgz",
"integrity": "sha512-TCZ36BjURTeFTM/CwRcViQlfkMvL1/vFISuNLO5GkcVm1+QHfbSiNqZuWeMFjj1/3+uAjXswgRk30j1kkLYJBQ==" "integrity": "sha512-TCZ36BjURTeFTM/CwRcViQlfkMvL1/vFISuNLO5GkcVm1+QHfbSiNqZuWeMFjj1/3+uAjXswgRk30j1kkLYJBQ=="
}, },
"mongodb": {
"version": "2.2.35",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.35.tgz",
"integrity": "sha512-3HGLucDg/8EeYMin3k+nFWChTA85hcYDCw1lPsWR6yV9A6RgKb24BkLiZ9ySZR+S0nfBjWoIUS7cyV6ceGx5Gg==",
"requires": {
"es6-promise": "3.2.1",
"mongodb-core": "2.1.19",
"readable-stream": "2.2.7"
},
"dependencies": {
"process-nextick-args": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
"integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
},
"readable-stream": {
"version": "2.2.7",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.7.tgz",
"integrity": "sha1-BwV6y+JGeyIELTb5jFrVBwVOlbE=",
"requires": {
"buffer-shims": "1.0.0",
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "1.0.0",
"process-nextick-args": "1.0.7",
"string_decoder": "1.0.3",
"util-deprecate": "1.0.2"
}
}
}
},
"mongodb-core": {
"version": "2.1.19",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.19.tgz",
"integrity": "sha512-Jt4AtWUkpuW03kRdYGxga4O65O1UHlFfvvInslEfLlGi+zDMxbBe3J2NVmN9qPJ957Mn6Iz0UpMtV80cmxCVxw==",
"requires": {
"bson": "1.0.6",
"require_optional": "1.0.1"
}
},
"ms": { "ms": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
@ -9813,6 +9968,22 @@
"resolve-from": "1.0.1" "resolve-from": "1.0.1"
} }
}, },
"require_optional": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
"requires": {
"resolve-from": "2.0.0",
"semver": "5.5.0"
},
"dependencies": {
"resolve-from": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
}
}
},
"requirejs": { "requirejs": {
"version": "2.3.5", "version": "2.3.5",
"resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.5.tgz", "resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.5.tgz",
@ -10536,6 +10707,11 @@
"tweetnacl": "0.14.5" "tweetnacl": "0.14.5"
} }
}, },
"stack-trace": {
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
"integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
},
"static-extend": { "static-extend": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz",
@ -11169,6 +11345,11 @@
"resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz",
"integrity": "sha1-WIeWa7WCpFA6QetST301ARgVphM=" "integrity": "sha1-WIeWa7WCpFA6QetST301ARgVphM="
}, },
"triple-beam": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.1.0.tgz",
"integrity": "sha1-KsOHyMS9BL0mxh34kaYHn4WS/hA="
},
"true-case-path": { "true-case-path": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/true-case-path/-/true-case-path-1.0.2.tgz", "resolved": "https://registry.npmjs.org/true-case-path/-/true-case-path-1.0.2.tgz",
@ -11816,6 +11997,41 @@
"string-width": "1.0.2" "string-width": "1.0.2"
} }
}, },
"winston": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/winston/-/winston-2.4.1.tgz",
"integrity": "sha512-k/+Dkzd39ZdyJHYkuaYmf4ff+7j+sCIy73UCOWHYA67/WXU+FF/Y6PF28j+Vy7qNRPHWO+dR+/+zkoQWPimPqg==",
"requires": {
"async": "1.0.0",
"colors": "1.0.3",
"cycle": "1.0.3",
"eyes": "0.1.8",
"isstream": "0.1.2",
"stack-trace": "0.0.10"
},
"dependencies": {
"async": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
"integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
},
"colors": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
"integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs="
}
}
},
"winston-mongodb": {
"version": "4.0.0-rc1",
"resolved": "https://registry.npmjs.org/winston-mongodb/-/winston-mongodb-4.0.0-rc1.tgz",
"integrity": "sha512-s+e27+3mHs86RJPpdECAi3SoBX96c5pgooJR/ZUBf03Yb4+Ygb901KAHIe9W2rz67lLSV3kGRsyLUmQ9FnAkWA==",
"requires": {
"@types/winston": "2.3.9",
"mongodb": "2.2.35",
"triple-beam": "1.1.0"
}
},
"wordwrap": { "wordwrap": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",

View File

@ -13,6 +13,7 @@
"backbone": "^1.3.3", "backbone": "^1.3.3",
"browserify": "^16.1.0", "browserify": "^16.1.0",
"cheerio": "^1.0.0-rc.2", "cheerio": "^1.0.0-rc.2",
"dark-sky-api": "^0.6.3",
"debug-logger": "^0.4.1", "debug-logger": "^0.4.1",
"elapsed": "0.0.7", "elapsed": "0.0.7",
"eslint": "^4.19.0", "eslint": "^4.19.0",
@ -35,6 +36,7 @@
"leaflet": "^1.3.1", "leaflet": "^1.3.1",
"lodash": "^4.17.5", "lodash": "^4.17.5",
"log4js": "^2.5.3", "log4js": "^2.5.3",
"log4js-node-mongodb": "^2.2.1",
"loggy": "^1.0.2", "loggy": "^1.0.2",
"memory-cache": "^0.2.0", "memory-cache": "^0.2.0",
"moment": "^2.21.0", "moment": "^2.21.0",
@ -48,6 +50,8 @@
"twitter": "^1.7.1", "twitter": "^1.7.1",
"uglifyify": "^4.0.5", "uglifyify": "^4.0.5",
"underscore": "^1.8.3", "underscore": "^1.8.3",
"winston": "^2.4.1",
"winston-mongodb": "^4.0.0-rc1",
"yelp-fusion": "^2.0.3" "yelp-fusion": "^2.0.3"
}, },
"devDependencies": { "devDependencies": {

View File

@ -21,7 +21,8 @@ const cache = apicache.middleware;
app.use(express.static(path.join(__dirname, sitePath))); app.use(express.static(path.join(__dirname, sitePath)));
app.get('/weather', cache('15 minutes'), (req, res) => { // app.get('/weather', cache('15 minutes'), (req, res) => {
app.get('/weather', (req, res) => {
if (req.query.hasOwnProperty('ll')) if (req.query.hasOwnProperty('ll'))
weather.doGetOpenWeather(req.query.ll) weather.doGetOpenWeather(req.query.ll)
@ -39,7 +40,9 @@ app.get('/weather', cache('15 minutes'), (req, res) => {
} }
}); });
app.get('/forecast', cache('15 minutes'), (req, res) => { // app.get('/forecast', cache('15 minutes'), (req, res) => {
app.get('/forecast', (req, res) => {
logger.info('/forecast');
if (req.query.hasOwnProperty('ll')) if (req.query.hasOwnProperty('ll'))
weather.doGetFullForcast(req.query.ll) weather.doGetFullForcast(req.query.ll)

11
server/lib/logger.js Normal file
View File

@ -0,0 +1,11 @@
const log4js = require('log4js'),
mongoAppender = require('log4js-node-mongodb');
log4js.addAppender(
mongoAppender.appender(
{ 'connectionString': 'localhost:27017/jubilee' }),
'audit'
);
module.exports = { log4js };

View File

@ -33,9 +33,15 @@ function getDailyForcast(dailyData) {
const h24 = (60 * 1000 * 60 * 24); const h24 = (60 * 1000 * 60 * 24);
const now = new Date().getTime(); const now = new Date().getTime();
const startOD = now - (now % h24); const startODBase = new Date();
startODBase.setHours(0, 0, 0, 0);
const startOD = startODBase.getTime();
const endOD = startOD + h24 - 1; const endOD = startOD + h24 - 1;
logger.debug('startOD', fecha.format(new Date(startOD), 'default'));
logger.debug('endOD', fecha.format(new Date(endOD), 'default'));
for (const item of data) { for (const item of data) {
const time = item.time * 1000; const time = item.time * 1000;
if (!(time < endOD)) { if (!(time < endOD)) {
@ -59,7 +65,6 @@ function toCompass(degrees) {
return ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'][Math.round(degrees / 11.25 / 2)]; return ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'][Math.round(degrees / 11.25 / 2)];
} }
function moonCalc(moonPhase) { function moonCalc(moonPhase) {
let output = ''; let output = '';
if (moonPhase === 0.0) if (moonPhase === 0.0)

View File

@ -1,13 +1,19 @@
const Client = require('request-json'); const Client = require('request-json');
const logger = require('log4js').getLogger('Weather');
const { log4js } = require('./lib/logger');
const logger = log4js.getLogger('Weather');
const weather = require('openweather-apis'); const weather = require('openweather-apis');
const { reduceWeather } = require('./reducers/weather'); const { reduceWeather } = require('./reducers/weather');
const request = require('request');
logger.level = 'debug'; logger.level = 'debug';
logger.label = 'Weather';
const openWeatherApiKey = process.env.openweatherAPI || '936a0ed9eb23b95cf08fc9f693c24264'; const openWeatherApiKey = process.env.openweatherAPI || '936a0ed9eb23b95cf08fc9f693c24264';
const darkskyApiKey = process.env.darkskyApiKey || '9ad2a41d420f3cf4960571bb886f710c'; const darkskyApiKey = process.env.darkskyApiKey || '9ad2a41d420f3cf4960571bb886f710c';
const dsURL = `https://api.darksky.net/forecast/${ darkskyApiKey }/`;
const DSclient = Client.createClient(`https://api.darksky.net/forecast/${ darkskyApiKey }/`); const DSclient = Client.createClient(`https://api.darksky.net/forecast/${ darkskyApiKey }/`);
weather.setAPPID(openWeatherApiKey); weather.setAPPID(openWeatherApiKey);
@ -44,6 +50,7 @@ function doGetOpenWeatherForecast(ll) {
function doGetDarkSkyWeather(ll) { function doGetDarkSkyWeather(ll) {
const query = `${ll}?units=uk2&exclude=daily,flags,minutely,hourly`; const query = `${ll}?units=uk2&exclude=daily,flags,minutely,hourly`;
logger.debug(`https://api.darksky.net/forecast/${ darkskyApiKey }/${query}`);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
DSclient.get(query, function(err, res, body) { DSclient.get(query, function(err, res, body) {
@ -57,7 +64,8 @@ function doGetDarkSkyWeather(ll) {
function doGetFullForcast(ll) { function doGetFullForcast(ll) {
const query = `${ll}?units=uk2&exclude=flags,minutely`; const query = `${ll}?units=uk2&exclude=flags,minutely`;
logger.debug('doGetFullForcast');
logger.debug(query);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
DSclient.get(query, function(err, res, body) { DSclient.get(query, function(err, res, body) {
if (err || !body || !body.currently) if (err || !body || !body.currently)
@ -70,4 +78,42 @@ function doGetFullForcast(ll) {
}); });
} }
module.exports = { doGetOpenWeather, doGetOpenWeatherForecast, doGetDarkSkyWeather, doGetFullForcast }; function doGetFullForcastV2(ll) {
const query = `${ll}?units=uk2&exclude=flags,minutely`;
logger.debug('doGetFullForcastV2');
const url = `${dsURL}${query}`;
logger.debug(url);
return new Promise(function(resolve, reject) {
request.get({ 'url':url }, function(err, resp, body) {
if (err) {
logger.error(err);
return reject(err);
}
// Logger.error(err);
// return reject(err);
// Throw err;
console.log;
const output = reduceWeather(body);
output.fullBody = JSON.parse(body);
output.timestamp = new Date().getTime();
console.log(output);
return resolve(output);
}, function(error, response, body) {
console.log(response);
if (response.statusCode !== 200) {
logger.error(response.statusCode);
logger.error(body);
return reject(error);
}
});
});
}
module.exports = { doGetOpenWeather, doGetOpenWeatherForecast, doGetDarkSkyWeather, doGetFullForcast, doGetFullForcastV2 };

View File

@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
const CACHE_VERSION = { 'version': '0.0.685' }; const CACHE_VERSION = { 'version': '0.0.689' };
const dataCacheName = 'jubileeData-v1'; const dataCacheName = 'jubileeData-v1';
const cacheName = 'jubilee-final-1'; const cacheName = 'jubilee-final-1';
const filesToCache = [ const filesToCache = [

View File

@ -116,10 +116,10 @@ const ForecastView = Backbone.View.extend({
</div> </div>
<h3>Wind & Pressure</h3> <h3>Wind & Pressure</h3>
<div class="mui-row"> <div class="mui-row">
<div class="mui-col-xs-3 mui--text-left mui--text-body2">Wind</div> <div class="mui-col-xs-6 mui-col-md-3 mui--text-left mui--text-body2">Wind</div>
<div class="mui-col-xs-3 mui--text-right mui--text-title"><%=windSpeed %><span class="mui--text-body1">km/h</span></div> <div class="mui-col-xs-6 mui-col-md-3 mui--text-right mui--text-title"><%=windSpeed %><span class="mui--text-body1">km/h</span></div>
<div class="mui-col-xs-3 mui--text-left mui--text-body2">Barometer</div> <div class="mui-col-xs-6 mui-col-md-3 mui--text-left mui--text-body2">Barometer</div>
<div class="mui-col-xs-3 mui--text-right mui--text-title"><%=pressure %><span class="mui--text-body1">mBar</span></div> <div class="mui-col-xs-6 mui-col-md-3 mui--text-right mui--text-title"><%=pressure %><span class="mui--text-body1">mBar</span></div>
</div> </div>
<h3>Sun & Moon</h3> <h3>Sun & Moon</h3>