2021-01-03 20:32:27 +01:00
|
|
|
|
// @author tykayn contact@cipherbliss.com www.cipherbliss.com
|
|
|
|
|
// imports
|
2022-01-10 10:29:30 +01:00
|
|
|
|
import utils from './utils';
|
|
|
|
|
import parserConfig from './config';
|
2021-01-05 13:26:42 +01:00
|
|
|
|
import { htmlEscape } from 'escape-goat';
|
2022-01-10 10:29:30 +01:00
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
import Parser from 'rss-parser';
|
|
|
|
|
|
|
|
|
|
const fetch = require('node-fetch');
|
2021-01-03 20:32:27 +01:00
|
|
|
|
let parser = new Parser();
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ==============================================='.blue);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ==== Rss Feeder for mobilizon - by tykayn ===='.blue);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ==============================================='.blue);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
if (parserConfig.debug) {
|
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log('configMobilizon'.blue, config);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
}
|
2021-01-03 20:44:23 +01:00
|
|
|
|
const utilsTools = new utils();
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// trouver si un évènement existe déjà par son titre
|
|
|
|
|
|
2021-01-05 13:26:42 +01:00
|
|
|
|
let createEventQueries = '';
|
2021-01-03 20:32:27 +01:00
|
|
|
|
let counterOfEventsToAdd = 0;
|
2021-01-05 11:48:41 +01:00
|
|
|
|
const addEventQuery = utilsTools.agendadulibre.addQuery;
|
|
|
|
|
const runCreationQuery = utilsTools.runCreationQuery;
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
|
|
|
|
(async () => {
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log('⌛ interroger la BDD mobilizon postgresql');
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
2021-01-05 13:26:42 +01:00
|
|
|
|
utilsTools.setupClientPostgresql();
|
2021-01-05 11:48:41 +01:00
|
|
|
|
|
|
|
|
|
await utilsTools.client.connect();
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log('✅ OK connecté à postgresql');
|
|
|
|
|
console.log(' ');
|
|
|
|
|
const res = await utilsTools.client.query('SELECT * from events');
|
|
|
|
|
console.log('💾 évènements enregistrés dans mobilizon : ', res.rows.length); // Hello world!
|
2022-01-10 11:06:31 +01:00
|
|
|
|
console.log('res', res);
|
2021-01-05 13:26:42 +01:00
|
|
|
|
utilsTools.localMobilizonEventsByTitle = res.rows;
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
|
|
|
|
if (parserConfig.askAgendaDuLibre) {
|
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ===================================================='.blue);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ==== demander à l\'agenda du libre son flux RSS ===='.blue);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ===================================================='.blue);
|
|
|
|
|
|
|
|
|
|
console.log('⌛ lecture du flux rss : ' + parserConfig.rss_feed_url);
|
|
|
|
|
fetch(parserConfig.rss_feed_url, { method: 'GET' })
|
|
|
|
|
|
2022-01-10 10:29:30 +01:00
|
|
|
|
.then((arrayOfEvents:any) => {
|
|
|
|
|
console.log('xml rss_feed_url count', Object.keys(arrayOfEvents).length);
|
2021-01-05 13:26:42 +01:00
|
|
|
|
|
|
|
|
|
});
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
|
|
|
|
let feed = await parser.parseURL(parserConfig.rss_feed_url);
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log('✅ flux rss obtenu');
|
2021-01-03 20:32:27 +01:00
|
|
|
|
console.log(feed.title);
|
|
|
|
|
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log('⚙️ interprétation des évènements');
|
2021-01-03 20:32:27 +01:00
|
|
|
|
console.log(
|
2021-01-05 13:26:42 +01:00
|
|
|
|
'⌛ trouver les évènements qui ne font pas partie de la BDD mobilizon postgresql',
|
2021-01-03 20:32:27 +01:00
|
|
|
|
);
|
2021-01-05 11:17:54 +01:00
|
|
|
|
feed.items.forEach((eventFound) => {
|
|
|
|
|
console.log(eventFound.title);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// console.log('item', item)
|
2021-01-05 11:17:54 +01:00
|
|
|
|
utilsTools.agendadulibre.doesEventExists(eventFound);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (parserConfig.askOsmCal) {
|
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ===================================================='.blue);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ==== demander à OSM cal ===='.blue);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ===================================================='.blue);
|
2021-01-05 11:17:54 +01:00
|
|
|
|
|
2021-01-05 13:26:42 +01:00
|
|
|
|
fetch(parserConfig.osmcal_url, { method: 'GET' })
|
2022-01-10 10:29:30 +01:00
|
|
|
|
.then((res:any) => res.json())
|
|
|
|
|
.then((arrayOfEvents:any) => {
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log('json osmcal count', arrayOfEvents.length);
|
2021-01-05 11:17:54 +01:00
|
|
|
|
|
2021-01-05 13:26:42 +01:00
|
|
|
|
utilsTools.writeFile('osmcal.json', arrayOfEvents, 'json');
|
2021-01-05 11:17:54 +01:00
|
|
|
|
|
2021-01-05 14:34:36 +01:00
|
|
|
|
console.log('arrayOfEvents[0]', arrayOfEvents[1])
|
|
|
|
|
utilsTools.osmcal.doesEventExists(arrayOfEvents[1])
|
|
|
|
|
|
2022-01-10 11:06:31 +01:00
|
|
|
|
let EventsToCreate:any = [];
|
|
|
|
|
|
|
|
|
|
arrayOfEvents.forEach((eventFound:any) => {
|
|
|
|
|
if(!utilsTools.osmcal.doesEventExists(eventFound)){
|
|
|
|
|
EventsToCreate.push(eventFound);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
utilsTools.createEventQueriesForApi(EventsToCreate)
|
|
|
|
|
|
2021-01-05 11:17:54 +01:00
|
|
|
|
});
|
2021-01-03 20:32:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 11:06:31 +01:00
|
|
|
|
if (parserConfig.runAddQueriesToMobilizonAPI) {
|
|
|
|
|
console.log(
|
|
|
|
|
'➕ rajouter les évènements manquants par l\'API GraphQL',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (parserConfig.runAddQueriesToMobilizonBDD) {
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 11:17:54 +01:00
|
|
|
|
console.log(
|
2022-01-10 10:29:30 +01:00
|
|
|
|
'➕ rajouter les évènements manquants à la base mobilizon',
|
2021-01-05 11:17:54 +01:00
|
|
|
|
);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
2021-01-05 13:26:42 +01:00
|
|
|
|
utilsTools.makeQuery();
|
|
|
|
|
utilsTools.runCreationQuery();
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ---------- '.green);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(counterOfEventsToAdd, ' évènements ajoutés '.green);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log(' ---------- '.green);
|
2021-01-03 20:32:27 +01:00
|
|
|
|
// @ts-ignore
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log('✅ fermer la connec postgresql');
|
|
|
|
|
await utilsTools.client.end();
|
2022-01-10 10:29:30 +01:00
|
|
|
|
console.log('✅ ça c\'est fait ');
|
2021-01-03 20:32:27 +01:00
|
|
|
|
}
|
2021-01-05 13:26:42 +01:00
|
|
|
|
|
2021-01-03 20:32:27 +01:00
|
|
|
|
})();
|
|
|
|
|
|
2021-01-05 13:26:42 +01:00
|
|
|
|
console.log('✅ hey ho', this);
|