-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrp.js
91 lines (62 loc) · 2.05 KB
/
scrp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//utilisation de la librairie puppeteer (peut néecessiter une installation via 'npm install puppeteer')
const puppeteer = require('puppeteer');
const fs = require('fs');
const express = require('express');
const app = express();
const data_refresh_interval = 60;
//fonction sleep
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
var data = {
altitude: "",
speed: "",
coordinates: ""
}
function get_data()
{
(async () => {
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto('https://www.astroviewer.net/iss/en/');
//on laisse le temps à la page de se charger correctement
await sleep(5000);
var alt = await page.evaluate(()=> {
let altitude = document.querySelector("#cockpit > div:nth-child(3) > p ").textContent;
return altitude;
});
var speed = await page.evaluate(()=> {
let sp = document.querySelector("#speed").textContent;
return sp;
});
var coordinates = await page.evaluate(()=> {
let coo = document.querySelector("#gpt").textContent;
return coo;
});
data = {
dateSource:
[{
altitude: alt,
speed: speed,
coordinates: coordinates
}]
}
console.log(alt);
console.log(speed);
console.log(coordinates);
await browser.close();
})();
}
get_data();
setInterval(get_data, data_refresh_interval*1000);
app.use(express.static('public'));
app.get('/data', async function(req, res) {
res.send(data);
});
app.get("/", function(req, res){
fs.readFile("index.html", "utf8", function (err, data) {res.send(data);});
});
app.disable('x-powered-by');
app.listen(8081, () => {
console.log('Bonjour sur ton nouveaux cite web')
});