This commit is contained in:
Tykayn 2022-08-05 21:30:04 +02:00 committed by tykayn
parent 7b28235897
commit 1c19e214bf

View File

@ -48,7 +48,7 @@ export default function getElementCartographique() {
const titleSelector = ""
return fs.readFile(__dirname + '/assets/documents/elements_carto_osm.html', 'utf8', function (err, html) {
return fs.readFile(__dirname + '/assets/documents/elements_carto_osm.html', 'utf8', function (err, html) {
if (err) {
return console.log(err);
}
@ -96,12 +96,16 @@ export default function getElementCartographique() {
result.value = $(element).text().trim();
}
if (i === 3) {
result.description = $(element).text().replace(' ','').trim();
result.description = $(element).text().replace(' ', '').replace(' ', '').trim();
}
// let cell = $(element).find("td");
// console.log($(cell[0]));
})
if (!result.key) {
console.log("ERROR no key found", $(cells).html())
throw Error('no key BOOOOOOOOOOH');
}
// const tableRow = foundTable[randNumber] // get one of all tables but the TOC
// console.log("keys", keys)
// console.log("foundTable[0]", foundTable[0].text())
@ -114,16 +118,51 @@ export default function getElementCartographique() {
// console.log("Description", cells[3])
// // console.log("icone", tableCells[4])
// console.log("photo", cells[5].find('img')?.attribs.href)
// aller chercher le lien
// si la clé est une description avec des espaces, faire un lien vers la Key
let pageLink = `FR:Tag:${result.key}=${result.value}`
if (result.value.indexOf(' ') !== -1) {
pageLink = `FR:Key:${result.key}`
}
result.link = `https://wiki.openstreetmap.org/wiki/${pageLink}`
const url = result.link
// get a random page wich is not a discussion
// certaines valeurs ont des espaces, donc pas utilisable en url
if (result.value.indexOf(' ') === -1) {
console.log("url", url)
rp(url).then(function (html) {
//success!
const descriptionStrophe = '';
const filteredHtml = $('.mw-parser-output', html).find('p')
console.log("filteredHtml", filteredHtml)
if (filteredHtml[0] && filteredHtml[0].text()) {
result.long_desc = filteredHtml[0].text();
} else if (filteredHtml[1] && filteredHtml[1].text()) {
result.long_desc = filteredHtml[1].text();
}
// console.log("result", result)
console.log("result.long_desc", result.long_desc)
// image de description:
let imgSelector = ".description a.image img"
const message = makePostMessageFromObj(result)
console.log("message", message)
}, (err)=>{
console.error(err)
})
} else {
console.log("result", result)
const message = makePostMessageFromObj(result)
console.log("message", message)
}
result.link = `https://wiki.openstreetmap.org/wiki/FR:Tag:${result.key}=${result.value}`
console.log("result", result)
// aller chercher le lien
// image de description:
let imgSelector = ".description a.image img"
const message = makePostMessageFromObj(result)
console.log("message", message)
return result;
});