From 4e510e57187ead774c1a2b7f15d6cbc17af554d6 Mon Sep 17 00:00:00 2001 From: tykayn Date: Tue, 5 Jan 2021 14:34:36 +0100 Subject: [PATCH] add nominatim reverse, osm link to coordinates for osmcal --- index.js | 16 ++---- sources_examples/nominatim_reverse.json | 22 ++++++++ utils.ts | 73 ++++++++++++++++++++++--- 3 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 sources_examples/nominatim_reverse.json diff --git a/index.js b/index.js index 3eaf44f..3c9eb07 100644 --- a/index.js +++ b/index.js @@ -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); + // }); }); } diff --git a/sources_examples/nominatim_reverse.json b/sources_examples/nominatim_reverse.json new file mode 100644 index 0000000..822868a --- /dev/null +++ b/sources_examples/nominatim_reverse.json @@ -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" + ] +} diff --git a/utils.ts b/utils.ts index 696fea7..453ed7f 100644 --- a/utils.ts +++ b/utils.ts @@ -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=[]; + localMobilizonEventsByTitle = []; + /** + * converters + */ + + geocoderNominatim(coords){ + // https://nominatim.openstreetmap.org/reverse?lat=&lon=& + 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 ` ` + } + 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+ '
'+ event.location.detailed + '
' + event.location.venue + '
' +event.url + '
' + event.coords[0]+','+event.coords[1]) + "'"; + let title = "'" + htmlEscape(this.osmcal.getTitle(event)) + "'"; + let content = "'" + htmlEscape(`${event.date.human}
${+event.url}
`) + "'"; + + if (event.location) { + content += `${event.location.detailed} ` + if (event.location.venue) { + content += `
+ ${event.location.venue}` + } + if (event.location.coords) { + content += `
` + 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) => {