Compare commits
4 Commits
86aa7bc3ae
...
4e510e5718
Author | SHA1 | Date | |
---|---|---|---|
4e510e5718 | |||
0bb0d27ead | |||
e5eea3f803 | |||
b5f108c571 |
@ -1,8 +0,0 @@
|
||||
exports.config = {
|
||||
feeder_mobilizon_user_id: "",
|
||||
db_name: "",
|
||||
db_user: "",
|
||||
db_pass: "",
|
||||
};
|
||||
|
||||
export {};
|
167
index.js
167
index.js
@ -1,122 +1,69 @@
|
||||
// @author tykayn contact@cipherbliss.com www.cipherbliss.com
|
||||
// imports
|
||||
import utils from "./utils.ts";
|
||||
import parserConfig from "./config.ts";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { htmlEscape } from "escape-goat";
|
||||
import Parser from "rss-parser";
|
||||
import { Client } from "pg";
|
||||
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 = (rssEvent) => {
|
||||
if (!createEventQueries) {
|
||||
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 ";
|
||||
}
|
||||
if (counterOfEventsToAdd) {
|
||||
createEventQueries += ` , `;
|
||||
}
|
||||
|
||||
let title = "'" + htmlEscape(rssEvent.title) + "'";
|
||||
let content = "'" + htmlEscape(rssEvent.content) + "'";
|
||||
let uuid = uuidv4();
|
||||
let uuidString = "'" + uuid + "'";
|
||||
let eventUrl =
|
||||
"'" + parserConfig.mobilizon_public_url + "/events/" + uuid + "'";
|
||||
let begins_on = "'" + utilsTools.convertRssDate(rssEvent.date) + "'";
|
||||
let ends_on = "'" + utilsTools.convertRssDate(rssEvent.date) + "'";
|
||||
let baseOptions =
|
||||
'{"offers": [], "program": null, "attendees": [], "show_end_time": true, "show_start_time": true, "comment_moderation": "allow_all", "anonymous_participation": true, "participation_condition": [], "show_participation_price": false, "maximum_attendee_capacity": 0, "remaining_attendee_capacity": 0, "hide_organizer_when_group_event": false, "show_remaining_attendee_capacity": false}';
|
||||
let baseStats =
|
||||
'{"creator": 1, "rejected": 0, "moderator": 0, "participant": 0, "not_approved": 0, "administrator": 0, "not_confirmed": 0}';
|
||||
// TODO complete with date conversion
|
||||
// begins_on , ends_on expecting date format like this: "2020-12-17 23:00:00"
|
||||
|
||||
createEventQueries += `( ${title}, ${content}, ${parserConfig.feeder_mobilizon_user_id}, 'now()','now()', ${uuidString}, ${eventUrl}, 'confirmed' , 'meeting', ${baseOptions}, ${baseStats}, ${begins_on} , ${ends_on} )`;
|
||||
|
||||
counterOfEventsToAdd++;
|
||||
};
|
||||
const runCreationQuery = async () => {
|
||||
createEventQueries = createEventQueries + ";";
|
||||
utilsTools.writeFile("event_creation_query.psql", createEventQueries);
|
||||
|
||||
if (createEventQueries) {
|
||||
console.log(" ");
|
||||
console.log(" ⚙️⚙️⚙️ ");
|
||||
console.log(" ");
|
||||
console.log(" createEventQueries");
|
||||
console.log(createEventQueries);
|
||||
|
||||
const res = await client.query(createEventQueries);
|
||||
console.log("res", res);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
const client = new Client({
|
||||
host: "localhost",
|
||||
user: parserConfig.db_user,
|
||||
password: parserConfig.db_pass,
|
||||
database: parserConfig.db_name,
|
||||
});
|
||||
const addEventQuery = utilsTools.agendadulibre.addQuery;
|
||||
const runCreationQuery = utilsTools.runCreationQuery;
|
||||
|
||||
(async () => {
|
||||
console.log("⌛ interroger la BDD mobilizon postgresql");
|
||||
console.log('⌛ interroger la BDD mobilizon postgresql');
|
||||
|
||||
await client.connect();
|
||||
console.log("✅ OK connecté à postgresql");
|
||||
console.log(" ");
|
||||
const res = await client.query("SELECT * from events");
|
||||
console.log("💾 évènements enregistrés dans mobilizon : ", res.rows.length); // Hello world!
|
||||
utilsTools.setupClientPostgresql();
|
||||
|
||||
utilsTools.postgresEventsExisting = res.rows;
|
||||
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!
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
|
||||
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);
|
||||
@ -126,46 +73,50 @@ const client = new Client({
|
||||
}
|
||||
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);
|
||||
// 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);
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
|
||||
await 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 client.end();
|
||||
|
||||
})();
|
||||
|
||||
exports = () => {
|
||||
console.log("hey ho", this);
|
||||
console.log('✅ hey ho', this);
|
||||
};
|
||||
|
22
sources_examples/nominatim_reverse.json
Normal file
22
sources_examples/nominatim_reverse.json
Normal 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"
|
||||
]
|
||||
}
|
@ -22,7 +22,10 @@
|
||||
"location": {
|
||||
"short": "Oberframmering, Landau an der Isar, Bavaria, Germany",
|
||||
"detailed": "online, Osterhofener Straße, Oberframmering, Bavaria, Germany",
|
||||
"coords": [12.749539, 48.688166],
|
||||
"coords": [
|
||||
12.749539,
|
||||
48.688166
|
||||
],
|
||||
"venue": "online"
|
||||
}
|
||||
},
|
||||
@ -39,7 +42,10 @@
|
||||
"location": {
|
||||
"short": "San Jose, California, United States",
|
||||
"detailed": "Online, East Santa Clara Street, Japantown, San Jose, California, United States",
|
||||
"coords": [-121.890583, 37.336191],
|
||||
"coords": [
|
||||
-121.890583,
|
||||
37.336191
|
||||
],
|
||||
"venue": "Online"
|
||||
}
|
||||
},
|
||||
@ -55,7 +61,10 @@
|
||||
"location": {
|
||||
"short": "Bochum, North Rhine-Westphalia, Germany",
|
||||
"detailed": "Jitsi, Boulevard, Innenstadt, Bochum, North Rhine-Westphalia, Germany",
|
||||
"coords": [7.219664, 51.481811],
|
||||
"coords": [
|
||||
7.219664,
|
||||
51.481811
|
||||
],
|
||||
"venue": "Jitsi"
|
||||
}
|
||||
},
|
||||
@ -71,7 +80,10 @@
|
||||
"location": {
|
||||
"short": "Dresden, Saxony, Germany",
|
||||
"detailed": "Online, Wilsdruffer Straße, Innere Altstadt, Dresden, Saxony, Germany",
|
||||
"coords": [13.738144, 51.049329],
|
||||
"coords": [
|
||||
13.738144,
|
||||
51.049329
|
||||
],
|
||||
"venue": "Online"
|
||||
}
|
||||
},
|
||||
@ -88,7 +100,10 @@
|
||||
"location": {
|
||||
"short": "Warsaw, Masovian Voivodeship, Poland",
|
||||
"detailed": "Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland",
|
||||
"coords": [21.006725, 52.231958],
|
||||
"coords": [
|
||||
21.006725,
|
||||
52.231958
|
||||
],
|
||||
"venue": "Poland"
|
||||
}
|
||||
},
|
||||
@ -104,7 +119,10 @@
|
||||
"location": {
|
||||
"short": "Großarl, Salzburg, Austria",
|
||||
"detailed": "Online, Ebengasse, Salzburg, Austria",
|
||||
"coords": [13.199959, 47.200034],
|
||||
"coords": [
|
||||
13.199959,
|
||||
47.200034
|
||||
],
|
||||
"venue": "Online"
|
||||
}
|
||||
},
|
||||
@ -131,7 +149,10 @@
|
||||
"location": {
|
||||
"short": "Tamia, Madhya Pradesh, India",
|
||||
"detailed": "India, Tamia, Madhya Pradesh, India",
|
||||
"coords": [78.667743, 22.351115],
|
||||
"coords": [
|
||||
78.667743,
|
||||
22.351115
|
||||
],
|
||||
"venue": "India"
|
||||
}
|
||||
},
|
||||
@ -148,7 +169,10 @@
|
||||
"location": {
|
||||
"short": "Zurich, Zurich, Switzerland",
|
||||
"detailed": "online bbb, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland",
|
||||
"coords": [8.546741, 47.376035],
|
||||
"coords": [
|
||||
8.546741,
|
||||
47.376035
|
||||
],
|
||||
"venue": "online bbb"
|
||||
}
|
||||
},
|
||||
@ -164,7 +188,10 @@
|
||||
"location": {
|
||||
"short": "Munich, Bavaria, Germany",
|
||||
"detailed": "Thiereckstraße, Altstadt-Lehel, Munich, Bavaria, Germany",
|
||||
"coords": [11.575382, 48.137108]
|
||||
"coords": [
|
||||
11.575382,
|
||||
48.137108
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -180,7 +207,10 @@
|
||||
"location": {
|
||||
"short": "Michigan, United States",
|
||||
"detailed": "Online, Chippewa Trail, Michigan, United States",
|
||||
"coords": [-84.682435, 43.621196],
|
||||
"coords": [
|
||||
-84.682435,
|
||||
43.621196
|
||||
],
|
||||
"venue": "Online"
|
||||
}
|
||||
},
|
||||
@ -197,7 +227,10 @@
|
||||
"location": {
|
||||
"short": "Kansas, United States",
|
||||
"detailed": "Online, County Road 412, Kansas, United States",
|
||||
"coords": [-98.550441, 39.224396],
|
||||
"coords": [
|
||||
-98.550441,
|
||||
39.224396
|
||||
],
|
||||
"venue": "Online"
|
||||
}
|
||||
},
|
||||
@ -213,7 +246,10 @@
|
||||
"location": {
|
||||
"short": "Berlin, Berlin, Germany",
|
||||
"detailed": "Online, Link zur Platform siehe Event-Website, Unter den Linden, Mitte, Berlin, Berlin, Germany",
|
||||
"coords": [13.38886, 52.517037],
|
||||
"coords": [
|
||||
13.38886,
|
||||
52.517037
|
||||
],
|
||||
"venue": "Online, Link zur Platform siehe Event-Website"
|
||||
}
|
||||
},
|
||||
@ -230,7 +266,10 @@
|
||||
"location": {
|
||||
"short": "Warsaw, Masovian Voivodeship, Poland",
|
||||
"detailed": "Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland",
|
||||
"coords": [21.006725, 52.231958],
|
||||
"coords": [
|
||||
21.006725,
|
||||
52.231958
|
||||
],
|
||||
"venue": "Poland"
|
||||
}
|
||||
},
|
||||
@ -246,7 +285,10 @@
|
||||
"location": {
|
||||
"short": "Lyon, Auvergne-Rhône-Alpes, France",
|
||||
"detailed": "online, Rue Juliette Récamier, Les Brotteaux, Lyon, Auvergne-Rhône-Alpes, France",
|
||||
"coords": [4.853832, 45.763808],
|
||||
"coords": [
|
||||
4.853832,
|
||||
45.763808
|
||||
],
|
||||
"venue": "online"
|
||||
}
|
||||
},
|
||||
@ -283,7 +325,10 @@
|
||||
"location": {
|
||||
"short": "Berlin, Berlin, Germany",
|
||||
"detailed": "Online, Link zur Platform siehe Wiki-Link, Unter den Linden, Mitte, Berlin, Berlin, Germany",
|
||||
"coords": [13.38886, 52.517037],
|
||||
"coords": [
|
||||
13.38886,
|
||||
52.517037
|
||||
],
|
||||
"venue": "Online, Link zur Platform siehe Wiki-Link"
|
||||
}
|
||||
},
|
||||
@ -299,7 +344,10 @@
|
||||
"location": {
|
||||
"short": "Lüneburg, Lower Saxony, Germany",
|
||||
"detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany",
|
||||
"coords": [10.412018, 53.245632]
|
||||
"coords": [
|
||||
10.412018,
|
||||
53.245632
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -315,7 +363,10 @@
|
||||
"location": {
|
||||
"short": "San Jose, California, United States",
|
||||
"detailed": "Online, East Santa Clara Street, Japantown, San Jose, California, United States",
|
||||
"coords": [-121.890583, 37.336191],
|
||||
"coords": [
|
||||
-121.890583,
|
||||
37.336191
|
||||
],
|
||||
"venue": "Online"
|
||||
}
|
||||
},
|
||||
@ -332,7 +383,10 @@
|
||||
"location": {
|
||||
"short": "Warsaw, Masovian Voivodeship, Poland",
|
||||
"detailed": "Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland",
|
||||
"coords": [21.006725, 52.231958],
|
||||
"coords": [
|
||||
21.006725,
|
||||
52.231958
|
||||
],
|
||||
"venue": "Poland"
|
||||
}
|
||||
},
|
||||
@ -348,7 +402,10 @@
|
||||
"location": {
|
||||
"short": "Bremen, Free Hanseatic City of Bremen, Germany",
|
||||
"detailed": "Online via Jitsi, Am Markt, Mitte, Bremen, Free Hanseatic City of Bremen, Germany",
|
||||
"coords": [8.807165, 53.07582],
|
||||
"coords": [
|
||||
8.807165,
|
||||
53.07582
|
||||
],
|
||||
"venue": "Online via Jitsi"
|
||||
}
|
||||
},
|
||||
@ -365,7 +422,10 @@
|
||||
"location": {
|
||||
"short": "Brussels, Brussels-Capital, Belgium",
|
||||
"detailed": "Online, 8, Grand Place, Brussels, Brussels-Capital, Belgium",
|
||||
"coords": [4.351697, 50.846557],
|
||||
"coords": [
|
||||
4.351697,
|
||||
50.846557
|
||||
],
|
||||
"venue": "Online"
|
||||
}
|
||||
},
|
||||
@ -382,7 +442,10 @@
|
||||
"location": {
|
||||
"short": "Warsaw, Masovian Voivodeship, Poland",
|
||||
"detailed": "Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland",
|
||||
"coords": [21.006725, 52.231958],
|
||||
"coords": [
|
||||
21.006725,
|
||||
52.231958
|
||||
],
|
||||
"venue": "Poland"
|
||||
}
|
||||
},
|
||||
@ -399,7 +462,10 @@
|
||||
"location": {
|
||||
"short": "San Jose, California, United States",
|
||||
"detailed": "Online, East Santa Clara Street, Japantown, San Jose, California, United States",
|
||||
"coords": [-121.890583, 37.336191],
|
||||
"coords": [
|
||||
-121.890583,
|
||||
37.336191
|
||||
],
|
||||
"venue": "Online"
|
||||
}
|
||||
},
|
||||
@ -415,7 +481,10 @@
|
||||
"location": {
|
||||
"short": "Munich, Bavaria, Germany",
|
||||
"detailed": "Thiereckstraße, Altstadt-Lehel, Munich, Bavaria, Germany",
|
||||
"coords": [11.575382, 48.137108]
|
||||
"coords": [
|
||||
11.575382,
|
||||
48.137108
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -431,7 +500,10 @@
|
||||
"location": {
|
||||
"short": "Zurich, Zurich, Switzerland",
|
||||
"detailed": "online bbb, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland",
|
||||
"coords": [8.546741, 47.376035],
|
||||
"coords": [
|
||||
8.546741,
|
||||
47.376035
|
||||
],
|
||||
"venue": "online bbb"
|
||||
}
|
||||
},
|
||||
@ -447,7 +519,10 @@
|
||||
"location": {
|
||||
"short": "Berlin, Berlin, Germany",
|
||||
"detailed": "Online, Link zur Platform siehe Event-Website, Unter den Linden, Mitte, Berlin, Berlin, Germany",
|
||||
"coords": [13.38886, 52.517037],
|
||||
"coords": [
|
||||
13.38886,
|
||||
52.517037
|
||||
],
|
||||
"venue": "Online, Link zur Platform siehe Event-Website"
|
||||
}
|
||||
},
|
||||
@ -473,7 +548,10 @@
|
||||
"location": {
|
||||
"short": "Lüneburg, Lower Saxony, Germany",
|
||||
"detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany",
|
||||
"coords": [10.412018, 53.245632]
|
||||
"coords": [
|
||||
10.412018,
|
||||
53.245632
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -489,7 +567,10 @@
|
||||
"location": {
|
||||
"short": "Zurich, Zurich, Switzerland",
|
||||
"detailed": "online oder cafe BQM, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland",
|
||||
"coords": [8.546741, 47.376035],
|
||||
"coords": [
|
||||
8.546741,
|
||||
47.376035
|
||||
],
|
||||
"venue": "online oder cafe BQM"
|
||||
}
|
||||
},
|
||||
@ -505,7 +586,10 @@
|
||||
"location": {
|
||||
"short": "Munich, Bavaria, Germany",
|
||||
"detailed": "Thiereckstraße, Altstadt-Lehel, Munich, Bavaria, Germany",
|
||||
"coords": [11.575382, 48.137108]
|
||||
"coords": [
|
||||
11.575382,
|
||||
48.137108
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -520,7 +604,10 @@
|
||||
"location": {
|
||||
"short": "Berlin, Berlin, Germany",
|
||||
"detailed": "Online, Link zur Platform siehe Event-Website, Unter den Linden, Mitte, Berlin, Berlin, Germany",
|
||||
"coords": [13.38886, 52.517037],
|
||||
"coords": [
|
||||
13.38886,
|
||||
52.517037
|
||||
],
|
||||
"venue": "Online, Link zur Platform siehe Event-Website"
|
||||
}
|
||||
},
|
||||
@ -546,7 +633,10 @@
|
||||
"location": {
|
||||
"short": "Lüneburg, Lower Saxony, Germany",
|
||||
"detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany",
|
||||
"coords": [10.412018, 53.245632]
|
||||
"coords": [
|
||||
10.412018,
|
||||
53.245632
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -561,7 +651,10 @@
|
||||
"location": {
|
||||
"short": "Lüneburg, Lower Saxony, Germany",
|
||||
"detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany",
|
||||
"coords": [10.412018, 53.245632]
|
||||
"coords": [
|
||||
10.412018,
|
||||
53.245632
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -587,7 +680,10 @@
|
||||
"location": {
|
||||
"short": "Zurich, Zurich, Switzerland",
|
||||
"detailed": "beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland",
|
||||
"coords": [8.546741, 47.376035],
|
||||
"coords": [
|
||||
8.546741,
|
||||
47.376035
|
||||
],
|
||||
"venue": "beim Studi-Café bQm (ETH), Zürich"
|
||||
}
|
||||
},
|
||||
@ -603,7 +699,10 @@
|
||||
"location": {
|
||||
"short": "Lüneburg, Lower Saxony, Germany",
|
||||
"detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany",
|
||||
"coords": [10.412018, 53.245632]
|
||||
"coords": [
|
||||
10.412018,
|
||||
53.245632
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -628,7 +727,10 @@
|
||||
"location": {
|
||||
"short": "Lüneburg, Lower Saxony, Germany",
|
||||
"detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany",
|
||||
"coords": [10.412018, 53.245632]
|
||||
"coords": [
|
||||
10.412018,
|
||||
53.245632
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -654,7 +756,10 @@
|
||||
"location": {
|
||||
"short": "Zurich, Zurich, Switzerland",
|
||||
"detailed": "beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland",
|
||||
"coords": [8.546741, 47.376035],
|
||||
"coords": [
|
||||
8.546741,
|
||||
47.376035
|
||||
],
|
||||
"venue": "beim Studi-Café bQm (ETH), Zürich"
|
||||
}
|
||||
},
|
||||
@ -671,7 +776,10 @@
|
||||
"location": {
|
||||
"short": "Zurich, Zurich, Switzerland",
|
||||
"detailed": "beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland",
|
||||
"coords": [8.546741, 47.376035],
|
||||
"coords": [
|
||||
8.546741,
|
||||
47.376035
|
||||
],
|
||||
"venue": "beim Studi-Café bQm (ETH), Zürich"
|
||||
}
|
||||
},
|
||||
@ -688,7 +796,10 @@
|
||||
"location": {
|
||||
"short": "Zurich, Zurich, Switzerland",
|
||||
"detailed": "beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland",
|
||||
"coords": [8.546741, 47.376035],
|
||||
"coords": [
|
||||
8.546741,
|
||||
47.376035
|
||||
],
|
||||
"venue": "beim Studi-Café bQm (ETH), Zürich"
|
||||
}
|
||||
},
|
||||
@ -705,7 +816,10 @@
|
||||
"location": {
|
||||
"short": "Nairobi, Nairobi, Kenya",
|
||||
"detailed": "Nairobi, Kenya, Uhuru Highway, Nairobi West, Nairobi, Nairobi, Kenya",
|
||||
"coords": [36.826061, -1.303169],
|
||||
"coords": [
|
||||
36.826061,
|
||||
-1.303169
|
||||
],
|
||||
"venue": "Nairobi, Kenya"
|
||||
}
|
||||
}
|
||||
|
182
utils.ts
182
utils.ts
@ -1,8 +1,55 @@
|
||||
// @ts-ignore
|
||||
import parserConfig from "./config.ts";
|
||||
import {v4 as uuidv4} from "uuid";
|
||||
import {Client} from "pg";
|
||||
import {htmlEscape} from "escape-goat";
|
||||
|
||||
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};`;
|
||||
this.writeFile("event_creation_query.psql", this.createEventQueries, "psql");
|
||||
}
|
||||
runCreationQuery = async () => {
|
||||
if (this.createEventQueries) {
|
||||
console.log(" ");
|
||||
console.log(" ⚙️⚙️⚙️ ");
|
||||
console.log(" ");
|
||||
console.log(" createEventQueries");
|
||||
console.log(this.createEventQueries);
|
||||
|
||||
const res = await this.client.query(this.createEventQueries);
|
||||
console.log("res", res);
|
||||
return res;
|
||||
} else {
|
||||
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")
|
||||
@ -14,17 +61,34 @@ 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);
|
||||
}
|
||||
|
||||
postgresEventsExisting = [];
|
||||
writeFile = (fileName, data) => {
|
||||
/**
|
||||
* file management
|
||||
*/
|
||||
writeFile = (fileName, data, formatData) => {
|
||||
let dataToSave = data;
|
||||
if (formatData == 'json') {
|
||||
dataToSave = JSON.stringify(data, null, 4)
|
||||
}
|
||||
// write file to disk
|
||||
fs.writeFile(
|
||||
`./sources_examples/${fileName}`,
|
||||
JSON.stringify(data),
|
||||
dataToSave,
|
||||
"utf8",
|
||||
(err) => {
|
||||
if (err) {
|
||||
@ -35,16 +99,118 @@ class utils {
|
||||
}
|
||||
);
|
||||
};
|
||||
osmCal = {
|
||||
|
||||
/** ==============================
|
||||
* importation sources
|
||||
*/
|
||||
|
||||
osmcal = {
|
||||
queryToAdd: "",
|
||||
doesEventExists: (event) => {},
|
||||
addQuery: (event) => {},
|
||||
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(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)
|
||||
|
||||
let uuid = uuidv4();
|
||||
let uuidString = "'" + uuid + "'";
|
||||
let eventUrl =
|
||||
"'" + parserConfig.mobilizon_public_url + "/events/" + uuid + "'";
|
||||
let begins_on = "'" + this.convertRssDate(event.date.start) + "'";
|
||||
let ends_on = "'" + this.convertRssDate(event.date.end) + "'";
|
||||
let baseOptions =
|
||||
'{"offers": [], "program": null, "attendees": [], "show_end_time": true, "show_start_time": true, "comment_moderation": "allow_all", "anonymous_participation": true, "participation_condition": [], "show_participation_price": false, "maximum_attendee_capacity": 0, "remaining_attendee_capacity": 0, "hide_organizer_when_group_event": false, "show_remaining_attendee_capacity": false}';
|
||||
let baseStats =
|
||||
'{"creator": 1, "rejected": 0, "moderator": 0, "participant": 0, "not_approved": 0, "administrator": 0, "not_confirmed": 0}';
|
||||
// begins_on , ends_on expecting date format like this: "2020-12-17 23:00:00"
|
||||
|
||||
this.osmcal.queryToAdd += `( ${title}, ${content}, ${parserConfig.feeder_mobilizon_user_id}, 'now()','now()', ${uuidString}, ${eventUrl}, 'confirmed' , 'meeting', ${baseOptions}, ${baseStats}, ${begins_on} , ${ends_on} )`;
|
||||
|
||||
|
||||
this.osmcal.counterOfEventsToAdd++;
|
||||
this.counterOfEventsToAdd++;
|
||||
|
||||
},
|
||||
};
|
||||
agendadulibre = {
|
||||
queryToAdd: "",
|
||||
doesEventExists: (event) => {},
|
||||
addQuery: (event) => {},
|
||||
counterOfEventsToAdd: 0,
|
||||
doesEventExists: (event) => {
|
||||
const eventAlreadyExists =
|
||||
-1 !== this.localMobilizonEventsByTitle.indexOf(event.title);
|
||||
if (!eventAlreadyExists) {
|
||||
if (parserConfig.debug) {
|
||||
console.log('ajouter l event ', htmlEscape(event.title));
|
||||
}
|
||||
this.agendadulibre.addQuery(event);
|
||||
}
|
||||
},
|
||||
addQuery: (event) => {
|
||||
if (this.agendadulibre.queryToAdd) {
|
||||
this.agendadulibre.queryToAdd += ` , `;
|
||||
}
|
||||
|
||||
let title = "'" + htmlEscape(event.title) + "'";
|
||||
let content = "'" + htmlEscape(event.content) + "'";
|
||||
let uuid = uuidv4();
|
||||
let uuidString = "'" + uuid + "'";
|
||||
let eventUrl =
|
||||
"'" + parserConfig.mobilizon_public_url + "/events/" + uuid + "'";
|
||||
let begins_on = "'" + this.convertRssDate(event.date) + "'";
|
||||
let ends_on = "'" + this.convertRssDate(event.date) + "'";
|
||||
let baseOptions =
|
||||
'{"offers": [], "program": null, "attendees": [], "show_end_time": true, "show_start_time": true, "comment_moderation": "allow_all", "anonymous_participation": true, "participation_condition": [], "show_participation_price": false, "maximum_attendee_capacity": 0, "remaining_attendee_capacity": 0, "hide_organizer_when_group_event": false, "show_remaining_attendee_capacity": false}';
|
||||
let baseStats =
|
||||
'{"creator": 1, "rejected": 0, "moderator": 0, "participant": 0, "not_approved": 0, "administrator": 0, "not_confirmed": 0}';
|
||||
// begins_on , ends_on expecting date format like this: "2020-12-17 23:00:00"
|
||||
|
||||
this.agendadulibre.queryToAdd += `( ${title}, ${content}, ${parserConfig.feeder_mobilizon_user_id}, 'now()','now()', ${uuidString}, ${eventUrl}, 'confirmed' , 'meeting', ${baseOptions}, ${baseStats}, ${begins_on} , ${ends_on} )`;
|
||||
|
||||
this.agendadulibre.counterOfEventsToAdd++;
|
||||
this.counterOfEventsToAdd++;
|
||||
}
|
||||
};
|
||||
|
||||
setupClientPostgresql = () => {
|
||||
this.client = new Client({
|
||||
host: "localhost",
|
||||
user: parserConfig.db_user,
|
||||
password: parserConfig.db_pass,
|
||||
database: parserConfig.db_name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default utils;
|
||||
|
Loading…
Reference in New Issue
Block a user