add nominatim reverse, osm link to coordinates for osmcal

This commit is contained in:
tykayn 2021-01-05 14:34:36 +01:00 committed by Baptiste Lemoine
parent 0bb0d27ead
commit 4e510e5718
3 changed files with 94 additions and 17 deletions

View File

@ -55,11 +55,6 @@ const runCreationQuery = utilsTools.runCreationQuery;
.then((arrayOfEvents) => {
console.log('xml rss_feed_url count', arrayOfEvents.length);
arrayOfEvents.forEach((eventFound) => {
console.log(eventFound.name);
// console.log('item', item)
utilsTools.osmcal.doesEventExists(eventFound);
});
});
let feed = await parser.parseURL(parserConfig.rss_feed_url);
@ -91,11 +86,12 @@ const runCreationQuery = utilsTools.runCreationQuery;
utilsTools.writeFile('osmcal.json', arrayOfEvents, 'json');
arrayOfEvents.forEach((eventFound) => {
console.log(eventFound.name);
// console.log('item', item)
utilsTools.osmcal.doesEventExists(eventFound);
});
console.log('arrayOfEvents[0]', arrayOfEvents[1])
utilsTools.osmcal.doesEventExists(arrayOfEvents[1])
// arrayOfEvents.forEach((eventFound) => {
// utilsTools.osmcal.doesEventExists(eventFound);
// });
});
}

View File

@ -0,0 +1,22 @@
{
"place_id": 257545391,
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
"osm_type": "relation",
"osm_id": 5753651,
"lat": "11.8447153",
"lon": "1.8991527451060923",
"display_name": "Tansarga, Tapoa, Est, Burkina Faso",
"address": {
"department": "Tansarga",
"province": "Tapoa",
"region": "Est",
"country": "Burkina Faso",
"country_code": "bf"
},
"boundingbox": [
"11.6508914",
"12.0385474",
"1.7610148",
"2.0502629"
]
}

View File

@ -9,6 +9,10 @@ const moment = require("moment");
const fs = require("fs");
class utils {
/**
* postgres functions
*/
client;
makeQuery = () => {
this.createEventQueries = `INSERT INTO events(title, description, organizer_actor_id,inserted_at,updated_at, uuid, url, status, category, options,participants_stats, begins_on, ends_on) VALUES ${this.agendadulibre.queryToAdd} ${this.osmcal.queryToAdd};`;
@ -29,11 +33,23 @@ class utils {
console.log(" DISABLED createEventQueries");
}
};
/**
* memorizing properties
*/
createEventQueries = "";
counterOfEventsToAdd = 0;
localMobilizonEventsByTitle = [];
/**
* converters
*/
geocoderNominatim(coords){
// https://nominatim.openstreetmap.org/reverse?lat=<value>&lon=<value>&<params>
console.log('https://nominatim.openstreetmap.org/reverse?lat='+coords[0]+'&lon='+coords[0])+'&format=json'
}
convertRssDate(rssDate) {
let converted = moment(rssDate)
.format("YYYY-MM-DD LTS")
@ -45,11 +61,25 @@ class utils {
return converted;
}
convertCoordinateLinkOsmCal(coords) {
this.geocoderNominatim(coords);
return ` <div class='coordinates'>
<a href='https://www.openstreetmap.org/directions?from=&to=${coords[0]}%2C${coords[1]}'>voir le lieu sur une carte
</a>
</div> `
}
testdateconvert() {
let converted = this.convertRssDate("2021-03-12T19:00:00Z");
console.log("converted", converted);
}
/**
* file management
*/
writeFile = (fileName, data, formatData) => {
let dataToSave = data;
if (formatData == 'json') {
@ -69,18 +99,47 @@ class utils {
}
);
};
/** ==============================
* importation sources
*/
osmcal = {
queryToAdd: "",
counterOfEventsToAdd: 0,
getTitle: (event) => {
return event.name;
//+ ' '+ event.location.short
},
doesEventExists: (event) => {
const eventAlreadyExists =
-1 !== this.localMobilizonEventsByTitle.indexOf(this.osmcal.getTitle(event));
if (!eventAlreadyExists) {
if (parserConfig.debug) {
console.log('ajouter l event ', htmlEscape(this.osmcal.getTitle(event)));
}
this.osmcal.addQuery(event);
}
},
addQuery: (event) => {
if (this.osmcal.queryToAdd) {
this.osmcal.queryToAdd += ` , `;
}
let title = "'" + htmlEscape(event.name+ ' '+ event.location.short) + "'";
let content = "'" + htmlEscape(event.date.human+ ' <br/>'+ event.location.detailed + ' <br/>' + event.location.venue + ' <br/>' +event.url + ' <br/>' + event.coords[0]+','+event.coords[1]) + "'";
let title = "'" + htmlEscape(this.osmcal.getTitle(event)) + "'";
let content = "'" + htmlEscape(`${event.date.human} <br/>${+event.url} <br/> `) + "'";
if (event.location) {
content += `${event.location.detailed} `
if (event.location.venue) {
content += ` <br/>
${event.location.venue}`
}
if (event.location.coords) {
content += ` <br/> ` + this.convertCoordinateLinkOsmCal(event.location.coords)
}
}
console.log(' ')
console.log(' title', title)
console.log(' content', content)
@ -108,14 +167,14 @@ class utils {
agendadulibre = {
queryToAdd: "",
counterOfEventsToAdd: 0,
doesEventExists: (rssEvent) => {
doesEventExists: (event) => {
const eventAlreadyExists =
-1 !== this.localMobilizonEventsByTitle.indexOf(rssEvent.title);
-1 !== this.localMobilizonEventsByTitle.indexOf(event.title);
if (!eventAlreadyExists) {
if (parserConfig.debug) {
console.log('ajouter l event ', htmlEscape(rssEvent.title));
console.log('ajouter l event ', htmlEscape(event.title));
}
this.agendadulibre.addQuery(rssEvent);
this.agendadulibre.addQuery(event);
}
},
addQuery: (event) => {