This commit is contained in:
Tykayn 2022-08-04 16:30:18 +02:00 committed by tykayn
parent abd22a4b2a
commit 6d19804851
3 changed files with 58460 additions and 17746 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<includedPredefinedLibrary name="Node.js Core" />
</component>
</project>

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,11 @@ import rp from "request-promise";
import $ from "cheerio";
function getRandomWikiOSMPage() {
import fs from "fs";
import path from 'path';
const __dirname = path.resolve();
function getRandomWikiOSMPage() {
// get all FR tags
// const url = "https://wiki.openstreetmap.org/w/index.php?title=Special:Categories&offset=FR&limit=500"
@ -13,7 +17,7 @@ import $ from "cheerio";
// get a random page wich is not a discussion
// const url = "https://wiki.openstreetmap.org/wiki/Special:Random?namespace=all-discussions%3B1%3B2%3B3%3B5%3B7%3B9%3B11%3B120%3B121%3B122%3B123%3B201%3B203&invert=1&limit=10&days=1&enhanced=1&namespace__202_color=c1&urlversion=2"
rp(url)
.then(function(html){
.then(function (html) {
//success!
const wikiUrls = [];
const filteredHtml = $('.mw-spcontent ul li a', html)
@ -29,17 +33,17 @@ import $ from "cheerio";
console.log(wikiUrls);
return wikiUrls;
})
.catch(function(err){
.catch(function (err) {
//handle error
console.error(err)
});
}
function getRandomElementOfArray(listItems){
return listItems[Math.floor(Math.random()*listItems.length)]
function getRandomElementOfArray(listItems) {
return listItems[Math.floor(Math.random() * listItems.length)]
}
export default function getElementCartographique(){
export default function getElementCartographique() {
const url = "https://wiki.openstreetmap.org/wiki/FR:%C3%89l%C3%A9ments_cartographiques"
const titleLink = "#toc a"
const listElementSelector = "#toc a"
@ -47,30 +51,34 @@ export default function getElementCartographique(){
// prendre une ligne de tableau au hasard correspondant à l'ID de la section
const titleSelector = ""
rp(url)
.then(function(html){
//success!
const wikiUrls = [];
const listOfLinks = $(titleLink, html)
console.log("filteredHtml.length", listOfLinks.length)
const selectedTocLink = getRandomElementOfArray(listOfLinks).attribs.href;
console.log("selectedTocLink", selectedTocLink)
const tableRow = getRandomElementOfArray($(`${selectedTocLink}`, html).parent('table').children('tr'))
const tableCells = $('td', tableRow)
console.log("tag key value", tableCells[1])
console.log("Description", tableCells[3])
console.log("icone", tableCells[4])
console.log("photo", tableCells[5])
return tableRow;
})
.catch(function(err){
//handle error
console.error(err)
});
fs.readFile( __dirname + '/assets/documents/elements_carto_osm.html', 'utf8', function (err, html) {
if (err) {
return console.log(err);
}
// console.log(data);
//success!
const wikiUrls = [];
const listOfLinks = $(titleLink, html)
console.log("filteredHtml.length", listOfLinks.length)
const selectedTocLink = getRandomElementOfArray(listOfLinks).attribs.href;
console.log("selectedTocLink", selectedTocLink)
const tableRow = getRandomElementOfArray($(`${selectedTocLink}`, html)).parents('.wikitable')
console.log("tableRow.length", tableRow.length)
// const tableCells = $('td', tableRow)
// console.log("tableRow.length", tableRow.length)
// console.log("tag key value", tableCells[1])
// console.log("Description", tableCells[3])
// console.log("icone", tableCells[4])
// console.log("photo", tableCells[5])
return tableRow;
});
}
function getQuery() {