32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
const express = require('express')
|
|
const axios = require("axios");
|
|
const cheerio = require("cheerio");
|
|
const app = express()
|
|
|
|
app.use(express.json())
|
|
|
|
|
|
/* API pour récupérer le compteur de la pétition Ox Citoyens en temps réel */
|
|
app.get("/getCompteurPetition", (req, res) => {
|
|
const debut = "Signatures : ".length;
|
|
var compteur = "0";
|
|
|
|
axios
|
|
.get("https://www.change.org/p/non-aux-2-antennes-4g-5g-quartier-ox-muret-31-collectif-ox-citoyens/")
|
|
.then((response) => {
|
|
const $ = cheerio.load(response.data, null, false);
|
|
|
|
let thermometer = $("div[data-qa='signature-thermometer']").parent().children(0).text();
|
|
compteur = thermometer.substring(debut, thermometer.indexOf("Prochain"));
|
|
console.log("Compteur = " + compteur);
|
|
|
|
res.send("<div align='center' style='font-size:88px; font-family:Lato,Helvetica,Arial,Lucida,sans-serif; color:white;'>" + compteur + "</div>");
|
|
})
|
|
.catch((err) => console.log("Fetch error " + err));
|
|
});
|
|
|
|
|
|
app.listen(5007, ()=> {
|
|
console.log("server started on port 5007")
|
|
});
|