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

38 lines
1.2 KiB
JavaScript

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
selectedPicture = pictureDescriptionOfTagSrc[0].attribs.src;
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")
}
}