From 9eb196aaa5b0c2da105befb5eab861159772f3be Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 8 Aug 2022 18:34:56 +0200 Subject: [PATCH] do not search for other element if found an existing wiki page --- helpers/wiki_osm.mjs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/helpers/wiki_osm.mjs b/helpers/wiki_osm.mjs index ddf770c..6a92a13 100644 --- a/helpers/wiki_osm.mjs +++ b/helpers/wiki_osm.mjs @@ -19,8 +19,9 @@ const __dirname = path.resolve(); const selectionOverrideOfSectionTable = ''; const selectionOverrideOfLineTable = ''; -// const reallySendToot = false; -const reallySendToot = false; +let foundExistingWikiPageInFrench = false; +// const reallySendToot = true; +const reallySendPost = false; function getRandomWikiOSMPage() { @@ -53,6 +54,10 @@ function getRandomWikiOSMPage() { } export default function getElementCartographique() { + if(foundExistingWikiPageInFrench){ + console.log("already found foundExistingWikiPageInFrench") + return; + } const url = "https://wiki.openstreetmap.org/wiki/FR:%C3%89l%C3%A9ments_cartographiques" const titleLink = "#toc a" const listElementSelector = "#toc a" @@ -129,6 +134,7 @@ export default function getElementCartographique() { console.error("ERROR no key found", $(cells).html()) console.error('no key BOOOOOOOOOOH'); getElementCartographique(); + return; } // aller chercher le lien @@ -144,7 +150,7 @@ export default function getElementCartographique() { // get a random page wich is not a discussion // certaines valeurs ont des espaces, donc pas utilisable en url - if (configPost.value.indexOf(' ') === -1) { + if (configPost.value.indexOf(' ') === -1 || configPost.value.indexOf('<') === -1 || configPost.value.indexOf('>') === -1) { console.log("url", url) rp(url).then(function (html) { @@ -159,7 +165,9 @@ export default function getElementCartographique() { // image de description: // let imgSelector = ".description a.image img" console.log("✅ cette page existe bien en Français sur le wiki OSM") + foundExistingWikiPageInFrench = true; sendMessageWikiTagOfTheDay(makePostMessageFromObj(configPost)) + return; }, (err) => { console.error(err.statusCode) @@ -174,6 +182,7 @@ export default function getElementCartographique() { }); console.log("bon spa tout ça on essaie une autre ligne") getElementCartographique() + return; } }) @@ -204,6 +213,10 @@ export default function getElementCartographique() { * @returns {*} */ function checkExistenceOfWebPage(url) { + if(foundExistingWikiPageInFrench){ + console.log("already found foundExistingWikiPageInFrench, no need to check other page", url) + return; + } return rp(url).then((html) => { console.log("oui cette page existe!", url) }, (err) => { @@ -268,12 +281,14 @@ const res = getElementCartographique() function sendMessageWikiTagOfTheDay(message) { + + let configPost = { author: 'curator', image: 'osm_default.jpg', message, // reallySendPost: true, - reallySendPost: reallySendToot, + reallySendPost: reallySendPost, } sendPostMastodon(configPost) } \ No newline at end of file