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';
|
|
|
|
|
|
|
|
|
|
// @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) {
|
2022-01-10 11:48:28 +01:00
|
|
|
|
// @ts-ignore
|
|
|
|
|
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
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
console.log('⌛ interroger la BDD mobilizon postgresql');
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
async function init() {
|
2021-01-05 11:48:41 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
utilsTools.setupClientPostgresql();
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
await utilsTools.client.connect();
|
|
|
|
|
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!
|
|
|
|
|
// console.log('res', res);
|
|
|
|
|
utilsTools.localMobilizonEventsByTitle = res.rows;
|
2021-01-05 11:17:54 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
if (parserConfig.askAgendaDuLibre) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(' ===================================================='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(' ==== demander à l\'agenda du libre son flux RSS ===='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(' ===================================================='.blue);
|
2021-01-05 11:17:54 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
console.log('⌛ lecture du flux rss : ' + parserConfig.rss_feed_url);
|
|
|
|
|
fetch(parserConfig.rss_feed_url, {method: 'GET'})
|
2021-01-05 11:17:54 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
.then((arrayOfEvents: any) => {
|
|
|
|
|
console.log('xml rss_feed_url count', Object.keys(arrayOfEvents).length);
|
2021-01-05 14:34:36 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
});
|
2022-01-10 11:06:31 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
let feed = await parser.parseURL(parserConfig.rss_feed_url);
|
|
|
|
|
console.log('✅ flux rss obtenu');
|
|
|
|
|
console.log(feed.title);
|
2022-01-10 11:06:31 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
console.log('⚙️ interprétation des évènements');
|
|
|
|
|
console.log(
|
|
|
|
|
'⌛ trouver les évènements qui ne font pas partie de la BDD mobilizon postgresql',
|
|
|
|
|
);
|
|
|
|
|
feed.items.forEach((eventFound) => {
|
|
|
|
|
console.log(eventFound.title);
|
|
|
|
|
// console.log('item', item)
|
|
|
|
|
utilsTools.agendadulibre.doesEventExists(eventFound);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (parserConfig.askOsmCal) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(' ===================================================='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(' ==== demander à OSM cal ===='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(' ===================================================='.blue);
|
|
|
|
|
|
|
|
|
|
fetch(parserConfig.osmcal_url, {method: 'GET'})
|
|
|
|
|
.then((res: any) => res.json())
|
|
|
|
|
.then((arrayOfEvents: any) => {
|
|
|
|
|
console.log('json osmcal count', arrayOfEvents.length);
|
|
|
|
|
|
|
|
|
|
// utilsTools.writeFile('osmcal.json', arrayOfEvents, 'json');
|
|
|
|
|
|
|
|
|
|
let EventsToCreate: any = [];
|
|
|
|
|
|
|
|
|
|
arrayOfEvents.forEach((eventFound: any) => {
|
|
|
|
|
if (!utilsTools.osmcal.doesEventExists(eventFound)) {
|
|
|
|
|
EventsToCreate.push(eventFound);
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
});
|
|
|
|
|
utilsTools.createEventQueriesForApi(EventsToCreate)
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parserConfig.runAddQueriesToMobilizonAPI) {
|
|
|
|
|
console.log(
|
|
|
|
|
'➕ rajouter les évènements manquants par l\'API GraphQL',
|
|
|
|
|
utilsTools.agendadulibre.queryToAdd.length
|
|
|
|
|
);
|
|
|
|
|
let limiter = true;
|
|
|
|
|
let counter = 0;
|
|
|
|
|
|
|
|
|
|
utilsTools.agendadulibre.queryToAdd.forEach((graphQLquery: any) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (limiter && !counter) {
|
|
|
|
|
counter++;
|
|
|
|
|
console.log('graphQLquery.variables.title', graphQLquery.variables.title);
|
|
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
|
operationName: "createEvent",
|
|
|
|
|
query: graphQLquery.query,
|
|
|
|
|
variables: graphQLquery.variables
|
|
|
|
|
}
|
|
|
|
|
// fetch(parserConfig.dev_url, {
|
|
|
|
|
// method: "post",
|
|
|
|
|
// body: JSON.stringify(body),
|
|
|
|
|
// headers: {"Content-Type": "application/json"}
|
|
|
|
|
// })
|
|
|
|
|
// .then(res => {
|
|
|
|
|
// res.json()
|
|
|
|
|
// console.log('succès');
|
|
|
|
|
// })
|
|
|
|
|
// .then(json => console.log(json))
|
|
|
|
|
// .catch(err => console.log(err))
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parserConfig.runAddQueriesToMobilizonBDD) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(
|
|
|
|
|
'➕ rajouter les évènements manquants à la base mobilizon',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
utilsTools.makeQuery();
|
|
|
|
|
utilsTools.runCreationQuery();
|
|
|
|
|
|
|
|
|
|
}
|
2022-01-10 11:06:31 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
});
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +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');
|
2022-01-10 11:48:28 +01:00
|
|
|
|
utilsTools.client.end();
|
2022-01-10 10:29:30 +01:00
|
|
|
|
console.log('✅ ça c\'est fait ');
|
2022-01-10 11:48:28 +01:00
|
|
|
|
console.log(' ');
|
|
|
|
|
}
|
2021-01-03 20:32:27 +01:00
|
|
|
|
|
2022-01-10 11:48:28 +01:00
|
|
|
|
(init)();
|
|
|
|
|
console.log('✅ hey ho', this);
|