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

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-12-14 18:18:34 +01:00
import fetch from "node-fetch"
import rp from "request-promise";
import $ from "cheerio";
import fs from "fs";
import path from 'path';
let url = 'https://wiki.openstreetmap.org/wiki/FR:Key:building:material';
let pictureDescrFinder = '.d_image img'
// 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)
return selectedPicture;
} else {
console.log("pas d'image de description dans le HTML")
}
}