multi-account-post-schedule.../helpers/osm_get_description_picture.mjs

34 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-12-14 18:18:34 +01:00
import $ from "cheerio";
let url = 'https://wiki.openstreetmap.org/wiki/FR:Key:building:material';
2025-01-12 12:28:59 +01:00
let pictureDescrFinder = '.d_image img'
2022-12-14 18:18:34 +01:00
// rp(url).then(function (html) {
// getSourceOfDescriptorPageContent(html)
// })
export function getSourceOfDescriptorPageContent(HTMLcontent) {
const pictureDescriptionOfTagSrc = $(pictureDescrFinder, HTMLcontent)
let selectedPicture = 'osm_default.jpg';
// image trouvée
if (pictureDescriptionOfTagSrc[0]) {
let sourcesSet = pictureDescriptionOfTagSrc[0].attribs.srcset
2023-03-03 17:28:41 +01:00
selectedPicture = pictureDescriptionOfTagSrc[0].attribs.src;
2022-12-14 18:18:34 +01:00
sourcesSet = sourcesSet.split(',')
console.log(sourcesSet.length)
// prendre l'image la plus grande du src set
if (sourcesSet.length > 1) {
selectedPicture = sourcesSet[sourcesSet.length - 1]
selectedPicture = selectedPicture.trim().split(' ')[0]
}
console.log(sourcesSet)
console.log(selectedPicture)
2025-01-12 12:28:59 +01:00
return `https://wiki.openstreetmap.org${selectedPicture.trim()}`;
2022-12-14 18:18:34 +01:00
} else {
console.log("pas d'image de description dans le HTML")
}
}