|
|
|
@ -1,75 +1,74 @@
|
|
|
|
|
// @author tykayn contact@cipherbliss.com www.cipherbliss.com
|
|
|
|
|
// imports
|
|
|
|
|
import utils from "./utils.ts";
|
|
|
|
|
import parserConfig from "./config.ts";
|
|
|
|
|
import { htmlEscape } from "escape-goat";
|
|
|
|
|
import Parser from "rss-parser";
|
|
|
|
|
const fetch = require("node-fetch");
|
|
|
|
|
import utils from './utils.ts';
|
|
|
|
|
import parserConfig from './config.ts';
|
|
|
|
|
import { htmlEscape } from 'escape-goat';
|
|
|
|
|
import Parser from 'rss-parser';
|
|
|
|
|
|
|
|
|
|
const fetch = require('node-fetch');
|
|
|
|
|
let parser = new Parser();
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ===============================================".blue);
|
|
|
|
|
console.log(' ==============================================='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ==== Rss Feeder for mobilizon - by tykayn ====".blue);
|
|
|
|
|
console.log(' ==== Rss Feeder for mobilizon - by tykayn ===='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ===============================================".blue);
|
|
|
|
|
console.log(' ==============================================='.blue);
|
|
|
|
|
if (parserConfig.debug) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log("configMobilizon".blue, config);
|
|
|
|
|
console.log('configMobilizon'.blue, config);
|
|
|
|
|
}
|
|
|
|
|
const utilsTools = new utils();
|
|
|
|
|
|
|
|
|
|
let localMobilizonEventsByTitle = [];
|
|
|
|
|
|
|
|
|
|
// trouver si un évènement existe déjà par son titre
|
|
|
|
|
const doesThisEventAlreadyExistInLocalEvents = (rssEvent) => {
|
|
|
|
|
const eventAlreadyExists =
|
|
|
|
|
-1 !== localMobilizonEventsByTitle.indexOf(rssEvent.title);
|
|
|
|
|
if (!eventAlreadyExists) {
|
|
|
|
|
if (parserConfig.debug) {
|
|
|
|
|
console.log("ajouter l event ", htmlEscape(rssEvent.title));
|
|
|
|
|
}
|
|
|
|
|
addEventQuery(rssEvent);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let createEventQueries = "";
|
|
|
|
|
let createEventQueries = '';
|
|
|
|
|
let counterOfEventsToAdd = 0;
|
|
|
|
|
const addEventQuery = utilsTools.agendadulibre.addQuery;
|
|
|
|
|
const runCreationQuery = utilsTools.runCreationQuery;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
|
console.log("⌛ interroger la BDD mobilizon postgresql");
|
|
|
|
|
console.log('⌛ interroger la BDD mobilizon postgresql');
|
|
|
|
|
|
|
|
|
|
utilsTools.setupClientPostgresql()
|
|
|
|
|
utilsTools.setupClientPostgresql();
|
|
|
|
|
|
|
|
|
|
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('✅ 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!
|
|
|
|
|
|
|
|
|
|
utilsTools.postgresEventsExisting = res.rows;
|
|
|
|
|
utilsTools.localMobilizonEventsByTitle = res.rows;
|
|
|
|
|
|
|
|
|
|
if (parserConfig.askAgendaDuLibre) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ====================================================".blue);
|
|
|
|
|
console.log(' ===================================================='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ==== demander à l'agenda du libre son flux RSS ====".blue);
|
|
|
|
|
console.log(' ==== demander à l\'agenda du libre son flux RSS ===='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ====================================================".blue);
|
|
|
|
|
console.log(' ===================================================='.blue);
|
|
|
|
|
|
|
|
|
|
console.log('⌛ lecture du flux rss : ' + parserConfig.rss_feed_url);
|
|
|
|
|
fetch(parserConfig.rss_feed_url, { method: 'GET' })
|
|
|
|
|
|
|
|
|
|
.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);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log("⌛ lecture du flux rss : " + parserConfig.rss_feed_url);
|
|
|
|
|
let feed = await parser.parseURL(parserConfig.rss_feed_url);
|
|
|
|
|
console.log("✅ flux rss obtenu");
|
|
|
|
|
utilsTools.writeFile("agenda_du_libre_feed.xml", feed);
|
|
|
|
|
console.log('✅ flux rss obtenu');
|
|
|
|
|
console.log(feed.title);
|
|
|
|
|
|
|
|
|
|
console.log("⚙️ interprétation des évènements");
|
|
|
|
|
console.log('⚙️ interprétation des évènements');
|
|
|
|
|
console.log(
|
|
|
|
|
"⌛ trouver les évènements qui ne font pas partie de la BDD mobilizon postgresql"
|
|
|
|
|
'⌛ trouver les évènements qui ne font pas partie de la BDD mobilizon postgresql',
|
|
|
|
|
);
|
|
|
|
|
feed.items.forEach((eventFound) => {
|
|
|
|
|
console.log(eventFound.title);
|
|
|
|
@ -79,18 +78,18 @@ const runCreationQuery = utilsTools.runCreationQuery;
|
|
|
|
|
}
|
|
|
|
|
if (parserConfig.askOsmCal) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ====================================================".blue);
|
|
|
|
|
console.log(' ===================================================='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ==== demander à OSM cal ====".blue);
|
|
|
|
|
console.log(' ==== demander à OSM cal ===='.blue);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ====================================================".blue);
|
|
|
|
|
console.log(' ===================================================='.blue);
|
|
|
|
|
|
|
|
|
|
fetch(parserConfig.osmcal_url, { method: "GET" })
|
|
|
|
|
fetch(parserConfig.osmcal_url, { method: 'GET' })
|
|
|
|
|
.then((res) => res.json())
|
|
|
|
|
.then((arrayOfEvents) => {
|
|
|
|
|
console.log("json osmcal count", arrayOfEvents.length);
|
|
|
|
|
console.log('json osmcal count', arrayOfEvents.length);
|
|
|
|
|
|
|
|
|
|
utilsTools.writeFile("osmcal.json", arrayOfEvents);
|
|
|
|
|
utilsTools.writeFile('osmcal.json', arrayOfEvents, 'json');
|
|
|
|
|
|
|
|
|
|
arrayOfEvents.forEach((eventFound) => {
|
|
|
|
|
console.log(eventFound.name);
|
|
|
|
@ -103,23 +102,25 @@ const runCreationQuery = utilsTools.runCreationQuery;
|
|
|
|
|
if (parserConfig.runAddQueriesToMobilizon) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(
|
|
|
|
|
"➕ rajouter les évènements manquants à la base mobilizon".blue
|
|
|
|
|
'➕ rajouter les évènements manquants à la base mobilizon'.blue,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
utilsTools.makeQuery();
|
|
|
|
|
utilsTools.runCreationQuery();
|
|
|
|
|
utilsTools.makeQuery();
|
|
|
|
|
utilsTools.runCreationQuery();
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ---------- ".green);
|
|
|
|
|
console.log(' ---------- '.green);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(counterOfEventsToAdd, " évènements ajoutés ".green);
|
|
|
|
|
console.log(counterOfEventsToAdd, ' évènements ajoutés '.green);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log(" ---------- ".green);
|
|
|
|
|
console.log(' ---------- '.green);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
console.log("✅ ça c'est fait ".green);
|
|
|
|
|
console.log('✅ fermer la connec postgresql');
|
|
|
|
|
await utilsTools.client.end();
|
|
|
|
|
console.log('✅ ça c\'est fait '.green);
|
|
|
|
|
}
|
|
|
|
|
await utilsTools.client.end();
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
exports = () => {
|
|
|
|
|
console.log("hey ho", this);
|
|
|
|
|
console.log('✅ hey ho', this);
|
|
|
|
|
};
|
|
|
|
|