hop
This commit is contained in:
parent
abd22a4b2a
commit
6d19804851
6
.idea/jsLibraryMappings.xml
Normal file
6
.idea/jsLibraryMappings.xml
Normal 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
@ -5,7 +5,11 @@ import rp from "request-promise";
|
|||||||
|
|
||||||
import $ from "cheerio";
|
import $ from "cheerio";
|
||||||
|
|
||||||
function getRandomWikiOSMPage() {
|
import fs from "fs";
|
||||||
|
import path from 'path';
|
||||||
|
const __dirname = path.resolve();
|
||||||
|
|
||||||
|
function getRandomWikiOSMPage() {
|
||||||
|
|
||||||
// get all FR tags
|
// get all FR tags
|
||||||
// const url = "https://wiki.openstreetmap.org/w/index.php?title=Special:Categories&offset=FR&limit=500"
|
// 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
|
// 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"
|
// 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)
|
rp(url)
|
||||||
.then(function(html){
|
.then(function (html) {
|
||||||
//success!
|
//success!
|
||||||
const wikiUrls = [];
|
const wikiUrls = [];
|
||||||
const filteredHtml = $('.mw-spcontent ul li a', html)
|
const filteredHtml = $('.mw-spcontent ul li a', html)
|
||||||
@ -29,17 +33,17 @@ import $ from "cheerio";
|
|||||||
console.log(wikiUrls);
|
console.log(wikiUrls);
|
||||||
return wikiUrls;
|
return wikiUrls;
|
||||||
})
|
})
|
||||||
.catch(function(err){
|
.catch(function (err) {
|
||||||
//handle error
|
//handle error
|
||||||
console.error(err)
|
console.error(err)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandomElementOfArray(listItems){
|
function getRandomElementOfArray(listItems) {
|
||||||
return listItems[Math.floor(Math.random()*listItems.length)]
|
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 url = "https://wiki.openstreetmap.org/wiki/FR:%C3%89l%C3%A9ments_cartographiques"
|
||||||
const titleLink = "#toc a"
|
const titleLink = "#toc a"
|
||||||
const listElementSelector = "#toc a"
|
const listElementSelector = "#toc a"
|
||||||
@ -47,8 +51,14 @@ export default function getElementCartographique(){
|
|||||||
// prendre une ligne de tableau au hasard correspondant à l'ID de la section
|
// prendre une ligne de tableau au hasard correspondant à l'ID de la section
|
||||||
const titleSelector = ""
|
const titleSelector = ""
|
||||||
|
|
||||||
rp(url)
|
|
||||||
.then(function(html){
|
fs.readFile( __dirname + '/assets/documents/elements_carto_osm.html', 'utf8', function (err, html) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err);
|
||||||
|
}
|
||||||
|
// console.log(data);
|
||||||
|
|
||||||
|
|
||||||
//success!
|
//success!
|
||||||
const wikiUrls = [];
|
const wikiUrls = [];
|
||||||
const listOfLinks = $(titleLink, html)
|
const listOfLinks = $(titleLink, html)
|
||||||
@ -56,20 +66,18 @@ export default function getElementCartographique(){
|
|||||||
const selectedTocLink = getRandomElementOfArray(listOfLinks).attribs.href;
|
const selectedTocLink = getRandomElementOfArray(listOfLinks).attribs.href;
|
||||||
console.log("selectedTocLink", selectedTocLink)
|
console.log("selectedTocLink", selectedTocLink)
|
||||||
|
|
||||||
const tableRow = getRandomElementOfArray($(`${selectedTocLink}`, html).parent('table').children('tr'))
|
const tableRow = getRandomElementOfArray($(`${selectedTocLink}`, html)).parents('.wikitable')
|
||||||
const tableCells = $('td', tableRow)
|
console.log("tableRow.length", tableRow.length)
|
||||||
console.log("tag key value", tableCells[1])
|
// const tableCells = $('td', tableRow)
|
||||||
console.log("Description", tableCells[3])
|
// console.log("tableRow.length", tableRow.length)
|
||||||
console.log("icone", tableCells[4])
|
// console.log("tag key value", tableCells[1])
|
||||||
console.log("photo", tableCells[5])
|
// console.log("Description", tableCells[3])
|
||||||
|
// console.log("icone", tableCells[4])
|
||||||
|
// console.log("photo", tableCells[5])
|
||||||
|
|
||||||
return tableRow;
|
return tableRow;
|
||||||
})
|
|
||||||
.catch(function(err){
|
|
||||||
//handle error
|
|
||||||
console.error(err)
|
|
||||||
});
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user