initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
node_modules/
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
48
index.js
Normal file
48
index.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const got = require('got');
|
||||||
|
const jsdom = require('jsdom');
|
||||||
|
|
||||||
|
const today = new Date();
|
||||||
|
const tomorrow = new Date(today);
|
||||||
|
tomorrow.setDate(today.getDate() + 1);
|
||||||
|
|
||||||
|
console.log(`QHM Portsmouth Shipping Movements for ${tomorrow.getDate()}/${tomorrow.getMonth() + 1}/${tomorrow.getFullYear()}`);
|
||||||
|
|
||||||
|
const URL = `https://www.royalnavy.mod.uk/qhm/portsmouth/shipping-movements/daily-movements?date=${tomorrow.getDate()}/${tomorrow.getMonth() + 1}/${tomorrow.getFullYear()}`
|
||||||
|
|
||||||
|
async function main()
|
||||||
|
{
|
||||||
|
const res = await got(URL);
|
||||||
|
const dom = new jsdom.JSDOM(res.body);
|
||||||
|
|
||||||
|
const table = dom.window.document.getElementsByClassName('qhm-shipping-movements')[0];
|
||||||
|
|
||||||
|
let output = [];
|
||||||
|
|
||||||
|
for (let i = 0, row; row = table.rows[i]; i++)
|
||||||
|
{
|
||||||
|
// Find vessel name
|
||||||
|
if (row.cells[2].innerHTML.includes('MV')) continue;
|
||||||
|
if (row.cells[2].innerHTML.includes('CLOSE')) continue;
|
||||||
|
if (row.cells[2].innerHTML.includes('OPEN')) continue;
|
||||||
|
|
||||||
|
let out = {
|
||||||
|
time: row.cells[1].innerHTML.trim().replace(/ +(?= )/g,''),
|
||||||
|
vessel: row.cells[2].innerHTML.trim().replace(/ +(?= )/g,''),
|
||||||
|
from: row.cells[3].innerHTML.trim().replace(/ +(?= )/g,''),
|
||||||
|
to: row.cells[4].innerHTML.trim().replace(/ +(?= )/g,''),
|
||||||
|
remarks: row.cells[6].innerHTML.trim().replace(/ +(?= )/g,'')
|
||||||
|
}
|
||||||
|
|
||||||
|
output.push(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
// format output
|
||||||
|
for (o of output)
|
||||||
|
{
|
||||||
|
console.log(`${o.vessel} movement at ${o.time}, from ${o.from} to ${o.to}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
15
package.json
Normal file
15
package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "qhmscraper",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "Ben Kyd <benjaminkyd@gmail.com> (https://benkyd.co.uk)",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"got": "^11.7.0",
|
||||||
|
"jsdom": "^16.4.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user