diff --git a/index.js b/index.js index 183b87c..5c6a644 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,8 @@ // 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"); let parser = new Parser(); @@ -37,65 +35,20 @@ const doesThisEventAlreadyExistInLocalEvents = (rssEvent) => { 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 += ` , `; - } +const addEventQuery = utilsTools.agendadulibre.addQuery; +const runCreationQuery = utilsTools.runCreationQuery; - 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, -}); (async () => { console.log("⌛ interroger la BDD mobilizon postgresql"); - await client.connect(); + utilsTools.setupClientPostgresql() + + await utilsTools.client.connect(); console.log("✅ OK connecté à postgresql"); console.log(" "); - const res = await client.query("SELECT * from events"); + 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; @@ -142,7 +95,7 @@ const client = new Client({ arrayOfEvents.forEach((eventFound) => { console.log(eventFound.name); // console.log('item', item) - utilsTools.osmCal.doesEventExists(eventFound); + utilsTools.osmcal.doesEventExists(eventFound); }); }); } @@ -153,7 +106,8 @@ const client = new Client({ "➕ rajouter les évènements manquants à la base mobilizon".blue ); - await runCreationQuery(); + utilsTools.makeQuery(); + utilsTools.runCreationQuery(); // @ts-ignore console.log(" ---------- ".green); // @ts-ignore @@ -163,7 +117,7 @@ const client = new Client({ // @ts-ignore console.log("✅ ça c'est fait ".green); } - await client.end(); + await utilsTools.client.end(); })(); exports = () => { diff --git a/sources_examples/osmcal.json b/sources_examples/osmcal.json index 147655e..48adfc3 100644 --- a/sources_examples/osmcal.json +++ b/sources_examples/osmcal.json @@ -1,712 +1 @@ -[ - { - "name": "Missing Maps London Mapathon", - "url": "https://osmcal.org/event/367/", - "date": { - "human": "5th January 19:00 – 21:00 (Europe/London)", - "human_short": "5th January", - "whole_day": false, - "start": "2021-01-05T19:00:00+00:00", - "end": "2021-01-05T21:00:00+00:00" - } - }, - { - "name": "Virtuelles Niederbayern-Treffen", - "url": "https://osmcal.org/event/404/", - "date": { - "human": "5th January", - "human_short": "5th January", - "whole_day": true, - "start": "2021-01-05T19:30:00+01:00" - }, - "location": { - "short": "Oberframmering, Landau an der Isar, Bavaria, Germany", - "detailed": "online, Osterhofener Straße, Oberframmering, Bavaria, Germany", - "coords": [12.749539, 48.688166], - "venue": "online" - } - }, - { - "name": "Virtual Civic Hack & Map Night", - "url": "https://osmcal.org/event/375/", - "date": { - "human": "7th January 18:30 – 21:00", - "human_short": "7th January", - "whole_day": false, - "start": "2021-01-07T18:30:00-08:00", - "end": "2021-01-07T21:00:00-08:00" - }, - "location": { - "short": "San Jose, California, United States", - "detailed": "Online, East Santa Clara Street, Japantown, San Jose, California, United States", - "coords": [-121.890583, 37.336191], - "venue": "Online" - } - }, - { - "name": "Bochum OSM-Stammtisch (online)", - "url": "https://osmcal.org/event/368/", - "date": { - "human": "7th January 19:00", - "human_short": "7th January", - "whole_day": false, - "start": "2021-01-07T19:00:00+01:00" - }, - "location": { - "short": "Bochum, North Rhine-Westphalia, Germany", - "detailed": "Jitsi, Boulevard, Innenstadt, Bochum, North Rhine-Westphalia, Germany", - "coords": [7.219664, 51.481811], - "venue": "Jitsi" - } - }, - { - "name": "Dresdner OSM-Stammtisch", - "url": "https://osmcal.org/event/410/", - "date": { - "human": "7th January 19:00", - "human_short": "7th January", - "whole_day": false, - "start": "2021-01-07T19:00:00+01:00" - }, - "location": { - "short": "Dresden, Saxony, Germany", - "detailed": "Online, Wilsdruffer Straße, Innere Altstadt, Dresden, Saxony, Germany", - "coords": [13.738144, 51.049329], - "venue": "Online" - } - }, - { - "name": "Virtual community meeting.", - "url": "https://osmcal.org/event/400/", - "date": { - "human": "8th January 19:00 – 22:00", - "human_short": "8th January", - "whole_day": false, - "start": "2021-01-08T19:00:00+00:00", - "end": "2021-01-08T22:00:00+00:00" - }, - "location": { - "short": "Warsaw, Masovian Voivodeship, Poland", - "detailed": "Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland", - "coords": [21.006725, 52.231958], - "venue": "Poland" - } - }, - { - "name": "Virtueller OSM Stammtisch Österreich", - "url": "https://osmcal.org/event/423/", - "date": { - "human": "8th January 19:00", - "human_short": "8th January", - "whole_day": false, - "start": "2021-01-08T19:00:00+01:00" - }, - "location": { - "short": "Großarl, Salzburg, Austria", - "detailed": "Online, Ebengasse, Salzburg, Austria", - "coords": [13.199959, 47.200034], - "venue": "Online" - } - }, - { - "name": "Virtual meeting of the Polish OSM Association", - "url": "https://osmcal.org/event/418/", - "date": { - "human": "9th January 19:00 (Etc/UTC)", - "human_short": "9th January", - "whole_day": false, - "start": "2021-01-09T19:00:00+00:00" - } - }, - { - "name": "Naksha 2021", - "url": "https://osmcal.org/event/422/", - "date": { - "human": "10th January 19:00 – 16th January 21:00", - "human_short": "10th–16th January", - "whole_day": false, - "start": "2021-01-10T19:00:00+05:30", - "end": "2021-01-16T21:00:00+05:30" - }, - "location": { - "short": "Tamia, Madhya Pradesh, India", - "detailed": "India, Tamia, Madhya Pradesh, India", - "coords": [78.667743, 22.351115], - "venue": "India" - } - }, - { - "name": "OSM-Treffen Zürich", - "url": "https://osmcal.org/event/417/", - "date": { - "human": "11th January 18:30 – 22:00", - "human_short": "11th January", - "whole_day": false, - "start": "2021-01-11T18:30:00+01:00", - "end": "2021-01-11T22:00:00+01:00" - }, - "location": { - "short": "Zurich, Zurich, Switzerland", - "detailed": "online bbb, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland", - "coords": [8.546741, 47.376035], - "venue": "online bbb" - } - }, - { - "name": "Münchner OSM-Stammtisch", - "url": "https://osmcal.org/event/419/", - "date": { - "human": "12th January 19:00", - "human_short": "12th January", - "whole_day": false, - "start": "2021-01-12T19:00:00+01:00" - }, - "location": { - "short": "Munich, Bavaria, Germany", - "detailed": "Thiereckstraße, Altstadt-Lehel, Munich, Bavaria, Germany", - "coords": [11.575382, 48.137108] - } - }, - { - "name": "Michigan Online Meetup", - "url": "https://osmcal.org/event/366/", - "date": { - "human": "13th January 19:00 – 20:00", - "human_short": "13th January", - "whole_day": false, - "start": "2021-01-13T19:00:00-05:00", - "end": "2021-01-13T20:00:00-05:00" - }, - "location": { - "short": "Michigan, United States", - "detailed": "Online, Chippewa Trail, Michigan, United States", - "coords": [-84.682435, 43.621196], - "venue": "Online" - } - }, - { - "name": "OpenStreetMap US Mappy Hour", - "url": "https://osmcal.org/event/405/", - "date": { - "human": "13th January 20:30 – 21:30", - "human_short": "13th January", - "whole_day": false, - "start": "2021-01-13T20:30:00-05:00", - "end": "2021-01-13T21:30:00-05:00" - }, - "location": { - "short": "Kansas, United States", - "detailed": "Online, County Road 412, Kansas, United States", - "coords": [-98.550441, 39.224396], - "venue": "Online" - } - }, - { - "name": "151. Berlin-Brandenburg OpenStreetMap Stammtisch (Online)", - "url": "https://osmcal.org/event/384/", - "date": { - "human": "14th January 19:00", - "human_short": "14th January", - "whole_day": false, - "start": "2021-01-14T19:00:00+01:00" - }, - "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], - "venue": "Online, Link zur Platform siehe Event-Website" - } - }, - { - "name": "Virtual community meeting.", - "url": "https://osmcal.org/event/401/", - "date": { - "human": "15th January 19:00 – 22:00", - "human_short": "15th January", - "whole_day": false, - "start": "2021-01-15T19:00:00+00:00", - "end": "2021-01-15T22:00:00+00:00" - }, - "location": { - "short": "Warsaw, Masovian Voivodeship, Poland", - "detailed": "Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland", - "coords": [21.006725, 52.231958], - "venue": "Poland" - } - }, - { - "name": "Rencontre mensuelle (virtuelle) Lyon", - "url": "https://osmcal.org/event/407/", - "date": { - "human": "19th January 18:30", - "human_short": "19th January", - "whole_day": false, - "start": "2021-01-19T18:30:00+01:00" - }, - "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], - "venue": "online" - } - }, - { - "name": "135. Treffen des OSM-Stammtisches Bonn", - "url": "https://osmcal.org/event/393/", - "date": { - "human": "19th January 19:00 (Europe/Berlin)", - "human_short": "19th January", - "whole_day": false, - "start": "2021-01-19T19:00:00+01:00" - } - }, - { - "name": "Missing Maps DRK Online Mapathon", - "url": "https://osmcal.org/event/380/", - "date": { - "human": "19th January 19:00 – 22:00 (Europe/Berlin)", - "human_short": "19th January", - "whole_day": false, - "start": "2021-01-19T19:00:00+01:00", - "end": "2021-01-19T22:00:00+01:00" - } - }, - { - "name": "OSM-Verkehrswende #19 (Online)", - "url": "https://osmcal.org/event/383/", - "date": { - "human": "19th January 19:30", - "human_short": "19th January", - "whole_day": false, - "start": "2021-01-19T19:30:00+01:00" - }, - "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], - "venue": "Online, Link zur Platform siehe Wiki-Link" - } - }, - { - "name": "Lüneburger Mappertreffen (online)", - "url": "https://osmcal.org/event/385/", - "date": { - "human": "19th January 20:30", - "human_short": "19th January", - "whole_day": false, - "start": "2021-01-19T20:30:00+01:00" - }, - "location": { - "short": "Lüneburg, Lower Saxony, Germany", - "detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany", - "coords": [10.412018, 53.245632] - } - }, - { - "name": "Virtual Civic Hack & Map Night", - "url": "https://osmcal.org/event/376/", - "date": { - "human": "21st January 18:30 – 21:00", - "human_short": "21st January", - "whole_day": false, - "start": "2021-01-21T18:30:00-08:00", - "end": "2021-01-21T21:00:00-08:00" - }, - "location": { - "short": "San Jose, California, United States", - "detailed": "Online, East Santa Clara Street, Japantown, San Jose, California, United States", - "coords": [-121.890583, 37.336191], - "venue": "Online" - } - }, - { - "name": "Virtual community meeting.", - "url": "https://osmcal.org/event/402/", - "date": { - "human": "22nd January 19:00 – 22:00", - "human_short": "22nd January", - "whole_day": false, - "start": "2021-01-22T19:00:00+00:00", - "end": "2021-01-22T22:00:00+00:00" - }, - "location": { - "short": "Warsaw, Masovian Voivodeship, Poland", - "detailed": "Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland", - "coords": [21.006725, 52.231958], - "venue": "Poland" - } - }, - { - "name": "Bremer Mappertreffen (Online)", - "url": "https://osmcal.org/event/406/", - "date": { - "human": "25th January 19:00", - "human_short": "25th January", - "whole_day": false, - "start": "2021-01-25T19:00:00+01:00" - }, - "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], - "venue": "Online via Jitsi" - } - }, - { - "name": "Virtual OpenStreetMap Belgium meeting", - "url": "https://osmcal.org/event/319/", - "date": { - "human": "26th January 20:00 – 22:00", - "human_short": "26th January", - "whole_day": false, - "start": "2021-01-26T20:00:00+01:00", - "end": "2021-01-26T22:00:00+01:00" - }, - "location": { - "short": "Brussels, Brussels-Capital, Belgium", - "detailed": "Online, 8, Grand Place, Brussels, Brussels-Capital, Belgium", - "coords": [4.351697, 50.846557], - "venue": "Online" - } - }, - { - "name": "Virtual community meeting.", - "url": "https://osmcal.org/event/403/", - "date": { - "human": "29th January 19:00 – 22:00", - "human_short": "29th January", - "whole_day": false, - "start": "2021-01-29T19:00:00+00:00", - "end": "2021-01-29T22:00:00+00:00" - }, - "location": { - "short": "Warsaw, Masovian Voivodeship, Poland", - "detailed": "Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland", - "coords": [21.006725, 52.231958], - "venue": "Poland" - } - }, - { - "name": "Virtual Civic Hack & Map Night", - "url": "https://osmcal.org/event/377/", - "date": { - "human": "4th February 18:30 – 21:00", - "human_short": "4th February", - "whole_day": false, - "start": "2021-02-04T18:30:00-08:00", - "end": "2021-02-04T21:00:00-08:00" - }, - "location": { - "short": "San Jose, California, United States", - "detailed": "Online, East Santa Clara Street, Japantown, San Jose, California, United States", - "coords": [-121.890583, 37.336191], - "venue": "Online" - } - }, - { - "name": "Münchner OSM-Stammtisch", - "url": "https://osmcal.org/event/420/", - "date": { - "human": "10th February 19:00", - "human_short": "10th February", - "whole_day": false, - "start": "2021-02-10T19:00:00+01:00" - }, - "location": { - "short": "Munich, Bavaria, Germany", - "detailed": "Thiereckstraße, Altstadt-Lehel, Munich, Bavaria, Germany", - "coords": [11.575382, 48.137108] - } - }, - { - "name": "OSM-Treffen Zürich", - "url": "https://osmcal.org/event/411/", - "date": { - "human": "11th February 18:30 – 22:00", - "human_short": "11th February", - "whole_day": false, - "start": "2021-02-11T18:30:00+01:00", - "end": "2021-02-11T22:00:00+01:00" - }, - "location": { - "short": "Zurich, Zurich, Switzerland", - "detailed": "online bbb, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland", - "coords": [8.546741, 47.376035], - "venue": "online bbb" - } - }, - { - "name": "152. Berlin-Brandenburg OpenStreetMap Stammtisch (Online)", - "url": "https://osmcal.org/event/408/", - "date": { - "human": "12th February 19:00", - "human_short": "12th February", - "whole_day": false, - "start": "2021-02-12T19:00:00+01:00" - }, - "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], - "venue": "Online, Link zur Platform siehe Event-Website" - } - }, - { - "name": "136. Treffen des OSM-Stammtisches Bonn", - "url": "https://osmcal.org/event/394/", - "date": { - "human": "16th February 20:00 (Europe/Berlin)", - "human_short": "16th February", - "whole_day": false, - "start": "2021-02-16T20:00:00+01:00" - } - }, - { - "name": "Lüneburger Mappertreffen (online)", - "url": "https://osmcal.org/event/386/", - "date": { - "human": "16th February 20:30", - "human_short": "16th February", - "whole_day": false, - "start": "2021-02-16T20:30:00+01:00" - }, - "location": { - "short": "Lüneburg, Lower Saxony, Germany", - "detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany", - "coords": [10.412018, 53.245632] - } - }, - { - "name": "OSM-Treffen Zürich", - "url": "https://osmcal.org/event/412/", - "date": { - "human": "11th March 18:30 – 22:00", - "human_short": "11th March", - "whole_day": false, - "start": "2021-03-11T18:30:00+01:00", - "end": "2021-03-11T22:00:00+01:00" - }, - "location": { - "short": "Zurich, Zurich, Switzerland", - "detailed": "online oder cafe BQM, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland", - "coords": [8.546741, 47.376035], - "venue": "online oder cafe BQM" - } - }, - { - "name": "Münchner OSM-Stammtisch", - "url": "https://osmcal.org/event/421/", - "date": { - "human": "11th March 19:00", - "human_short": "11th March", - "whole_day": false, - "start": "2021-03-11T19:00:00+01:00" - }, - "location": { - "short": "Munich, Bavaria, Germany", - "detailed": "Thiereckstraße, Altstadt-Lehel, Munich, Bavaria, Germany", - "coords": [11.575382, 48.137108] - } - }, - { - "name": "153. Berlin-Brandenburg OpenStreetMap Stammtisch (Online)", - "url": "https://osmcal.org/event/409/", - "date": { - "human": "11th March 19:00", - "human_short": "11th March", - "whole_day": false, - "start": "2021-03-11T19:00:00+01:00" - }, - "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], - "venue": "Online, Link zur Platform siehe Event-Website" - } - }, - { - "name": "137. Treffen des OSM-Stammtisches Bonn", - "url": "https://osmcal.org/event/395/", - "date": { - "human": "16th March 20:00 (Europe/Berlin)", - "human_short": "16th March", - "whole_day": false, - "start": "2021-03-16T20:00:00+01:00" - } - }, - { - "name": "Lüneburger Mappertreffen (online)", - "url": "https://osmcal.org/event/387/", - "date": { - "human": "16th March 20:30", - "human_short": "16th March", - "whole_day": false, - "start": "2021-03-16T20:30:00+01:00" - }, - "location": { - "short": "Lüneburg, Lower Saxony, Germany", - "detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany", - "coords": [10.412018, 53.245632] - } - }, - { - "name": "Lüneburger Mappertreffen (online)", - "url": "https://osmcal.org/event/388/", - "date": { - "human": "20th April 20:30", - "human_short": "20th April", - "whole_day": false, - "start": "2021-04-20T20:30:00+02:00" - }, - "location": { - "short": "Lüneburg, Lower Saxony, Germany", - "detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany", - "coords": [10.412018, 53.245632] - } - }, - { - "name": "138. Treffen des OSM-Stammtisches Bonn", - "url": "https://osmcal.org/event/396/", - "date": { - "human": "20th April 21:00 (Europe/Berlin)", - "human_short": "20th April", - "whole_day": false, - "start": "2021-04-20T21:00:00+02:00" - } - }, - { - "name": "OSM-Treffen Zürich", - "url": "https://osmcal.org/event/413/", - "date": { - "human": "11th May 18:30 – 22:00", - "human_short": "11th May", - "whole_day": false, - "start": "2021-05-11T18:30:00+02:00", - "end": "2021-05-11T22:00:00+02:00" - }, - "location": { - "short": "Zurich, Zurich, Switzerland", - "detailed": "beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland", - "coords": [8.546741, 47.376035], - "venue": "beim Studi-Café bQm (ETH), Zürich" - } - }, - { - "name": "Lüneburger Mappertreffen (online)", - "url": "https://osmcal.org/event/389/", - "date": { - "human": "18th May 20:30", - "human_short": "18th May", - "whole_day": false, - "start": "2021-05-18T20:30:00+02:00" - }, - "location": { - "short": "Lüneburg, Lower Saxony, Germany", - "detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany", - "coords": [10.412018, 53.245632] - } - }, - { - "name": "139. Treffen des OSM-Stammtisches Bonn", - "url": "https://osmcal.org/event/397/", - "date": { - "human": "18th May 21:00 (Europe/Berlin)", - "human_short": "18th May", - "whole_day": false, - "start": "2021-05-18T21:00:00+02:00" - } - }, - { - "name": "Lüneburger Mappertreffen (online)", - "url": "https://osmcal.org/event/391/", - "date": { - "human": "15th June 20:30", - "human_short": "15th June", - "whole_day": false, - "start": "2021-06-15T20:30:00+02:00" - }, - "location": { - "short": "Lüneburg, Lower Saxony, Germany", - "detailed": "9, Friedenstraße, Rotes Feld, Lower Saxony, Germany", - "coords": [10.412018, 53.245632] - } - }, - { - "name": "140. Treffen des OSM-Stammtisches Bonn", - "url": "https://osmcal.org/event/398/", - "date": { - "human": "15th June 21:00 (Europe/Berlin)", - "human_short": "15th June", - "whole_day": false, - "start": "2021-06-15T21:00:00+02:00" - } - }, - { - "name": "OSM-Treffen Zürich", - "url": "https://osmcal.org/event/414/", - "date": { - "human": "11th August 18:30 – 22:00", - "human_short": "11th August", - "whole_day": false, - "start": "2021-08-11T18:30:00+02:00", - "end": "2021-08-11T22:00:00+02:00" - }, - "location": { - "short": "Zurich, Zurich, Switzerland", - "detailed": "beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland", - "coords": [8.546741, 47.376035], - "venue": "beim Studi-Café bQm (ETH), Zürich" - } - }, - { - "name": "OSM-Treffen Zürich", - "url": "https://osmcal.org/event/415/", - "date": { - "human": "11th October 18:30 – 22:00", - "human_short": "11th October", - "whole_day": false, - "start": "2021-10-11T18:30:00+02:00", - "end": "2021-10-11T22:00:00+02:00" - }, - "location": { - "short": "Zurich, Zurich, Switzerland", - "detailed": "beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland", - "coords": [8.546741, 47.376035], - "venue": "beim Studi-Café bQm (ETH), Zürich" - } - }, - { - "name": "OSM-Treffen Zürich", - "url": "https://osmcal.org/event/416/", - "date": { - "human": "11th November 18:30 – 22:00", - "human_short": "11th November", - "whole_day": false, - "start": "2021-11-11T18:30:00+01:00", - "end": "2021-11-11T22:00:00+01:00" - }, - "location": { - "short": "Zurich, Zurich, Switzerland", - "detailed": "beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland", - "coords": [8.546741, 47.376035], - "venue": "beim Studi-Café bQm (ETH), Zürich" - } - }, - { - "name": "State of the Map Africa 2021", - "url": "https://osmcal.org/event/392/", - "date": { - "human": "19th November – 21st November", - "human_short": "19th–21st November", - "whole_day": true, - "start": "2021-11-19T12:00:00+03:00", - "end": "2021-11-21T12:00:00+03:00" - }, - "location": { - "short": "Nairobi, Nairobi, Kenya", - "detailed": "Nairobi, Kenya, Uhuru Highway, Nairobi West, Nairobi, Nairobi, Kenya", - "coords": [36.826061, -1.303169], - "venue": "Nairobi, Kenya" - } - } -] +[{"name":"Missing Maps London Mapathon","url":"https://osmcal.org/event/367/","date":{"human":"5th January 19:00 – 21:00 (Europe/London)","human_short":"5th January","whole_day":false,"start":"2021-01-05T19:00:00+00:00","end":"2021-01-05T21:00:00+00:00"}},{"name":"Virtuelles Niederbayern-Treffen","url":"https://osmcal.org/event/404/","date":{"human":"5th January","human_short":"5th January","whole_day":true,"start":"2021-01-05T19:30:00+01:00"},"location":{"short":"Oberframmering, Landau an der Isar, Bavaria, Germany","detailed":"online, Osterhofener Straße, Oberframmering, Bavaria, Germany","coords":[12.749539,48.688166],"venue":"online"}},{"name":"Virtual Civic Hack & Map Night","url":"https://osmcal.org/event/375/","date":{"human":"7th January 18:30 – 21:00","human_short":"7th January","whole_day":false,"start":"2021-01-07T18:30:00-08:00","end":"2021-01-07T21:00:00-08:00"},"location":{"short":"San Jose, California, United States","detailed":"Online, East Santa Clara Street, Japantown, San Jose, California, United States","coords":[-121.890583,37.336191],"venue":"Online"}},{"name":"Bochum OSM-Stammtisch (online)","url":"https://osmcal.org/event/368/","date":{"human":"7th January 19:00","human_short":"7th January","whole_day":false,"start":"2021-01-07T19:00:00+01:00"},"location":{"short":"Bochum, North Rhine-Westphalia, Germany","detailed":"Jitsi, Boulevard, Innenstadt, Bochum, North Rhine-Westphalia, Germany","coords":[7.219664,51.481811],"venue":"Jitsi"}},{"name":"Dresdner OSM-Stammtisch","url":"https://osmcal.org/event/410/","date":{"human":"7th January 19:00","human_short":"7th January","whole_day":false,"start":"2021-01-07T19:00:00+01:00"},"location":{"short":"Dresden, Saxony, Germany","detailed":"Online, Wilsdruffer Straße, Innere Altstadt, Dresden, Saxony, Germany","coords":[13.738144,51.049329],"venue":"Online"}},{"name":"Virtual community meeting.","url":"https://osmcal.org/event/400/","date":{"human":"8th January 19:00 – 22:00","human_short":"8th January","whole_day":false,"start":"2021-01-08T19:00:00+00:00","end":"2021-01-08T22:00:00+00:00"},"location":{"short":"Warsaw, Masovian Voivodeship, Poland","detailed":"Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland","coords":[21.006725,52.231958],"venue":"Poland"}},{"name":"Virtueller OSM Stammtisch Österreich","url":"https://osmcal.org/event/423/","date":{"human":"8th January 19:00","human_short":"8th January","whole_day":false,"start":"2021-01-08T19:00:00+01:00"},"location":{"short":"Großarl, Salzburg, Austria","detailed":"Online, Ebengasse, Salzburg, Austria","coords":[13.199959,47.200034],"venue":"Online"}},{"name":"Virtual meeting of the Polish OSM Association","url":"https://osmcal.org/event/418/","date":{"human":"9th January 19:00 (Etc/UTC)","human_short":"9th January","whole_day":false,"start":"2021-01-09T19:00:00+00:00"}},{"name":"Naksha 2021","url":"https://osmcal.org/event/422/","date":{"human":"10th January 19:00 – 16th January 21:00","human_short":"10th–16th January","whole_day":false,"start":"2021-01-10T19:00:00+05:30","end":"2021-01-16T21:00:00+05:30"},"location":{"short":"Tamia, Madhya Pradesh, India","detailed":"India, Tamia, Madhya Pradesh, India","coords":[78.667743,22.351115],"venue":"India"}},{"name":"OSM-Treffen Zürich","url":"https://osmcal.org/event/417/","date":{"human":"11th January 18:30 – 22:00","human_short":"11th January","whole_day":false,"start":"2021-01-11T18:30:00+01:00","end":"2021-01-11T22:00:00+01:00"},"location":{"short":"Zurich, Zurich, Switzerland","detailed":"online bbb, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland","coords":[8.546741,47.376035],"venue":"online bbb"}},{"name":"Münchner OSM-Stammtisch","url":"https://osmcal.org/event/419/","date":{"human":"12th January 19:00","human_short":"12th January","whole_day":false,"start":"2021-01-12T19:00:00+01:00"},"location":{"short":"Munich, Bavaria, Germany","detailed":"Thiereckstraße, Altstadt-Lehel, Munich, Bavaria, Germany","coords":[11.575382,48.137108]}},{"name":"Michigan Online Meetup","url":"https://osmcal.org/event/366/","date":{"human":"13th January 19:00 – 20:00","human_short":"13th January","whole_day":false,"start":"2021-01-13T19:00:00-05:00","end":"2021-01-13T20:00:00-05:00"},"location":{"short":"Michigan, United States","detailed":"Online, Chippewa Trail, Michigan, United States","coords":[-84.682435,43.621196],"venue":"Online"}},{"name":"OpenStreetMap US Mappy Hour","url":"https://osmcal.org/event/405/","date":{"human":"13th January 20:30 – 21:30","human_short":"13th January","whole_day":false,"start":"2021-01-13T20:30:00-05:00","end":"2021-01-13T21:30:00-05:00"},"location":{"short":"Kansas, United States","detailed":"Online, County Road 412, Kansas, United States","coords":[-98.550441,39.224396],"venue":"Online"}},{"name":"151. Berlin-Brandenburg OpenStreetMap Stammtisch (Online)","url":"https://osmcal.org/event/384/","date":{"human":"14th January 19:00","human_short":"14th January","whole_day":false,"start":"2021-01-14T19:00:00+01:00"},"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],"venue":"Online, Link zur Platform siehe Event-Website"}},{"name":"Virtual community meeting.","url":"https://osmcal.org/event/401/","date":{"human":"15th January 19:00 – 22:00","human_short":"15th January","whole_day":false,"start":"2021-01-15T19:00:00+00:00","end":"2021-01-15T22:00:00+00:00"},"location":{"short":"Warsaw, Masovian Voivodeship, Poland","detailed":"Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland","coords":[21.006725,52.231958],"venue":"Poland"}},{"name":"Rencontre mensuelle (virtuelle) Lyon","url":"https://osmcal.org/event/407/","date":{"human":"19th January 18:30","human_short":"19th January","whole_day":false,"start":"2021-01-19T18:30:00+01:00"},"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],"venue":"online"}},{"name":"135. Treffen des OSM-Stammtisches Bonn","url":"https://osmcal.org/event/393/","date":{"human":"19th January 19:00 (Europe/Berlin)","human_short":"19th January","whole_day":false,"start":"2021-01-19T19:00:00+01:00"}},{"name":"Missing Maps DRK Online Mapathon","url":"https://osmcal.org/event/380/","date":{"human":"19th January 19:00 – 22:00 (Europe/Berlin)","human_short":"19th January","whole_day":false,"start":"2021-01-19T19:00:00+01:00","end":"2021-01-19T22:00:00+01:00"}},{"name":"OSM-Verkehrswende #19 (Online)","url":"https://osmcal.org/event/383/","date":{"human":"19th January 19:30","human_short":"19th January","whole_day":false,"start":"2021-01-19T19:30:00+01:00"},"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],"venue":"Online, Link zur Platform siehe Wiki-Link"}},{"name":"Lüneburger Mappertreffen (online)","url":"https://osmcal.org/event/385/","date":{"human":"19th January 20:30","human_short":"19th January","whole_day":false,"start":"2021-01-19T20:30:00+01:00"},"location":{"short":"Lüneburg, Lower Saxony, Germany","detailed":"9, Friedenstraße, Rotes Feld, Lower Saxony, Germany","coords":[10.412018,53.245632]}},{"name":"Virtual Civic Hack & Map Night","url":"https://osmcal.org/event/376/","date":{"human":"21st January 18:30 – 21:00","human_short":"21st January","whole_day":false,"start":"2021-01-21T18:30:00-08:00","end":"2021-01-21T21:00:00-08:00"},"location":{"short":"San Jose, California, United States","detailed":"Online, East Santa Clara Street, Japantown, San Jose, California, United States","coords":[-121.890583,37.336191],"venue":"Online"}},{"name":"Virtual community meeting.","url":"https://osmcal.org/event/402/","date":{"human":"22nd January 19:00 – 22:00","human_short":"22nd January","whole_day":false,"start":"2021-01-22T19:00:00+00:00","end":"2021-01-22T22:00:00+00:00"},"location":{"short":"Warsaw, Masovian Voivodeship, Poland","detailed":"Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland","coords":[21.006725,52.231958],"venue":"Poland"}},{"name":"Bremer Mappertreffen (Online)","url":"https://osmcal.org/event/406/","date":{"human":"25th January 19:00","human_short":"25th January","whole_day":false,"start":"2021-01-25T19:00:00+01:00"},"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],"venue":"Online via Jitsi"}},{"name":"Virtual OpenStreetMap Belgium meeting","url":"https://osmcal.org/event/319/","date":{"human":"26th January 20:00 – 22:00","human_short":"26th January","whole_day":false,"start":"2021-01-26T20:00:00+01:00","end":"2021-01-26T22:00:00+01:00"},"location":{"short":"Brussels, Brussels-Capital, Belgium","detailed":"Online, 8, Grand Place, Brussels, Brussels-Capital, Belgium","coords":[4.351697,50.846557],"venue":"Online"}},{"name":"Virtual community meeting.","url":"https://osmcal.org/event/403/","date":{"human":"29th January 19:00 – 22:00","human_short":"29th January","whole_day":false,"start":"2021-01-29T19:00:00+00:00","end":"2021-01-29T22:00:00+00:00"},"location":{"short":"Warsaw, Masovian Voivodeship, Poland","detailed":"Poland, 1, Plac Defilad, Śródmieście, Warsaw, Masovian Voivodeship, Poland","coords":[21.006725,52.231958],"venue":"Poland"}},{"name":"Virtual Civic Hack & Map Night","url":"https://osmcal.org/event/377/","date":{"human":"4th February 18:30 – 21:00","human_short":"4th February","whole_day":false,"start":"2021-02-04T18:30:00-08:00","end":"2021-02-04T21:00:00-08:00"},"location":{"short":"San Jose, California, United States","detailed":"Online, East Santa Clara Street, Japantown, San Jose, California, United States","coords":[-121.890583,37.336191],"venue":"Online"}},{"name":"Münchner OSM-Stammtisch","url":"https://osmcal.org/event/420/","date":{"human":"10th February 19:00","human_short":"10th February","whole_day":false,"start":"2021-02-10T19:00:00+01:00"},"location":{"short":"Munich, Bavaria, Germany","detailed":"Thiereckstraße, Altstadt-Lehel, Munich, Bavaria, Germany","coords":[11.575382,48.137108]}},{"name":"OSM-Treffen Zürich","url":"https://osmcal.org/event/411/","date":{"human":"11th February 18:30 – 22:00","human_short":"11th February","whole_day":false,"start":"2021-02-11T18:30:00+01:00","end":"2021-02-11T22:00:00+01:00"},"location":{"short":"Zurich, Zurich, Switzerland","detailed":"online bbb, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland","coords":[8.546741,47.376035],"venue":"online bbb"}},{"name":"152. Berlin-Brandenburg OpenStreetMap Stammtisch (Online)","url":"https://osmcal.org/event/408/","date":{"human":"12th February 19:00","human_short":"12th February","whole_day":false,"start":"2021-02-12T19:00:00+01:00"},"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],"venue":"Online, Link zur Platform siehe Event-Website"}},{"name":"136. Treffen des OSM-Stammtisches Bonn","url":"https://osmcal.org/event/394/","date":{"human":"16th February 20:00 (Europe/Berlin)","human_short":"16th February","whole_day":false,"start":"2021-02-16T20:00:00+01:00"}},{"name":"Lüneburger Mappertreffen (online)","url":"https://osmcal.org/event/386/","date":{"human":"16th February 20:30","human_short":"16th February","whole_day":false,"start":"2021-02-16T20:30:00+01:00"},"location":{"short":"Lüneburg, Lower Saxony, Germany","detailed":"9, Friedenstraße, Rotes Feld, Lower Saxony, Germany","coords":[10.412018,53.245632]}},{"name":"OSM-Treffen Zürich","url":"https://osmcal.org/event/412/","date":{"human":"11th March 18:30 – 22:00","human_short":"11th March","whole_day":false,"start":"2021-03-11T18:30:00+01:00","end":"2021-03-11T22:00:00+01:00"},"location":{"short":"Zurich, Zurich, Switzerland","detailed":"online oder cafe BQM, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland","coords":[8.546741,47.376035],"venue":"online oder cafe BQM"}},{"name":"Münchner OSM-Stammtisch","url":"https://osmcal.org/event/421/","date":{"human":"11th March 19:00","human_short":"11th March","whole_day":false,"start":"2021-03-11T19:00:00+01:00"},"location":{"short":"Munich, Bavaria, Germany","detailed":"Thiereckstraße, Altstadt-Lehel, Munich, Bavaria, Germany","coords":[11.575382,48.137108]}},{"name":"153. Berlin-Brandenburg OpenStreetMap Stammtisch (Online)","url":"https://osmcal.org/event/409/","date":{"human":"11th March 19:00","human_short":"11th March","whole_day":false,"start":"2021-03-11T19:00:00+01:00"},"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],"venue":"Online, Link zur Platform siehe Event-Website"}},{"name":"137. Treffen des OSM-Stammtisches Bonn","url":"https://osmcal.org/event/395/","date":{"human":"16th March 20:00 (Europe/Berlin)","human_short":"16th March","whole_day":false,"start":"2021-03-16T20:00:00+01:00"}},{"name":"Lüneburger Mappertreffen (online)","url":"https://osmcal.org/event/387/","date":{"human":"16th March 20:30","human_short":"16th March","whole_day":false,"start":"2021-03-16T20:30:00+01:00"},"location":{"short":"Lüneburg, Lower Saxony, Germany","detailed":"9, Friedenstraße, Rotes Feld, Lower Saxony, Germany","coords":[10.412018,53.245632]}},{"name":"Lüneburger Mappertreffen (online)","url":"https://osmcal.org/event/388/","date":{"human":"20th April 20:30","human_short":"20th April","whole_day":false,"start":"2021-04-20T20:30:00+02:00"},"location":{"short":"Lüneburg, Lower Saxony, Germany","detailed":"9, Friedenstraße, Rotes Feld, Lower Saxony, Germany","coords":[10.412018,53.245632]}},{"name":"138. Treffen des OSM-Stammtisches Bonn","url":"https://osmcal.org/event/396/","date":{"human":"20th April 21:00 (Europe/Berlin)","human_short":"20th April","whole_day":false,"start":"2021-04-20T21:00:00+02:00"}},{"name":"OSM-Treffen Zürich","url":"https://osmcal.org/event/413/","date":{"human":"11th May 18:30 – 22:00","human_short":"11th May","whole_day":false,"start":"2021-05-11T18:30:00+02:00","end":"2021-05-11T22:00:00+02:00"},"location":{"short":"Zurich, Zurich, Switzerland","detailed":"beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland","coords":[8.546741,47.376035],"venue":"beim Studi-Café bQm (ETH), Zürich"}},{"name":"Lüneburger Mappertreffen (online)","url":"https://osmcal.org/event/389/","date":{"human":"18th May 20:30","human_short":"18th May","whole_day":false,"start":"2021-05-18T20:30:00+02:00"},"location":{"short":"Lüneburg, Lower Saxony, Germany","detailed":"9, Friedenstraße, Rotes Feld, Lower Saxony, Germany","coords":[10.412018,53.245632]}},{"name":"139. Treffen des OSM-Stammtisches Bonn","url":"https://osmcal.org/event/397/","date":{"human":"18th May 21:00 (Europe/Berlin)","human_short":"18th May","whole_day":false,"start":"2021-05-18T21:00:00+02:00"}},{"name":"Lüneburger Mappertreffen (online)","url":"https://osmcal.org/event/391/","date":{"human":"15th June 20:30","human_short":"15th June","whole_day":false,"start":"2021-06-15T20:30:00+02:00"},"location":{"short":"Lüneburg, Lower Saxony, Germany","detailed":"9, Friedenstraße, Rotes Feld, Lower Saxony, Germany","coords":[10.412018,53.245632]}},{"name":"140. Treffen des OSM-Stammtisches Bonn","url":"https://osmcal.org/event/398/","date":{"human":"15th June 21:00 (Europe/Berlin)","human_short":"15th June","whole_day":false,"start":"2021-06-15T21:00:00+02:00"}},{"name":"OSM-Treffen Zürich","url":"https://osmcal.org/event/414/","date":{"human":"11th August 18:30 – 22:00","human_short":"11th August","whole_day":false,"start":"2021-08-11T18:30:00+02:00","end":"2021-08-11T22:00:00+02:00"},"location":{"short":"Zurich, Zurich, Switzerland","detailed":"beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland","coords":[8.546741,47.376035],"venue":"beim Studi-Café bQm (ETH), Zürich"}},{"name":"OSM-Treffen Zürich","url":"https://osmcal.org/event/415/","date":{"human":"11th October 18:30 – 22:00","human_short":"11th October","whole_day":false,"start":"2021-10-11T18:30:00+02:00","end":"2021-10-11T22:00:00+02:00"},"location":{"short":"Zurich, Zurich, Switzerland","detailed":"beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland","coords":[8.546741,47.376035],"venue":"beim Studi-Café bQm (ETH), Zürich"}},{"name":"OSM-Treffen Zürich","url":"https://osmcal.org/event/416/","date":{"human":"11th November 18:30 – 22:00","human_short":"11th November","whole_day":false,"start":"2021-11-11T18:30:00+01:00","end":"2021-11-11T22:00:00+01:00"},"location":{"short":"Zurich, Zurich, Switzerland","detailed":"beim Studi-Café bQm (ETH), Zürich, Hochstrasse, Fluntern, Zurich, Zurich, Switzerland","coords":[8.546741,47.376035],"venue":"beim Studi-Café bQm (ETH), Zürich"}},{"name":"State of the Map Africa 2021","url":"https://osmcal.org/event/392/","date":{"human":"19th November – 21st November","human_short":"19th–21st November","whole_day":true,"start":"2021-11-19T12:00:00+03:00","end":"2021-11-21T12:00:00+03:00"},"location":{"short":"Nairobi, Nairobi, Kenya","detailed":"Nairobi, Kenya, Uhuru Highway, Nairobi West, Nairobi, Nairobi, Kenya","coords":[36.826061,-1.303169],"venue":"Nairobi, Kenya"}}] \ No newline at end of file diff --git a/utils.ts b/utils.ts index d0df581..c4db8c9 100644 --- a/utils.ts +++ b/utils.ts @@ -1,50 +1,121 @@ +// @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 { - convertRssDate(rssDate) { - let converted = moment(rssDate) - .format("YYYY-MM-DD LTS") - .slice(0, -3) - .concat(".000000"); // in js format like 2021-03-12T19:00:00Z + 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); + } + runCreationQuery = async () => { + if (this.createEventQueries) { + console.log(" "); + console.log(" ⚙️⚙️⚙️ "); + console.log(" "); + console.log(" createEventQueries"); + console.log(this.createEventQueries); - console.log("converted", converted); - // like 2021-01-03 15:31:02.918940 - return converted; - } - - testdateconvert() { - let converted = this.convertRssDate("2021-03-12T19:00:00Z"); - console.log("converted", converted); - } - - postgresEventsExisting = []; - writeFile = (fileName, data) => { - // write file to disk - fs.writeFile( - `./sources_examples/${fileName}`, - JSON.stringify(data), - "utf8", - (err) => { - if (err) { - console.log(`Error writing file: ${err}`); + const res = await this.client.query(this.createEventQueries); + console.log("res", res); + return res; } else { - console.log(`File ${fileName} is written successfully!`); + console.log(" DISABLED createEventQueries"); } - } - ); - }; - osmCal = { - queryToAdd: "", - doesEventExists: (event) => {}, - addQuery: (event) => {}, - }; - agendadulibre = { - queryToAdd: "", - doesEventExists: (event) => {}, - addQuery: (event) => {}, - }; + }; + createEventQueries = ""; + counterOfEventsToAdd = 0; + + + convertRssDate(rssDate) { + let converted = moment(rssDate) + .format("YYYY-MM-DD LTS") + .slice(0, -3) + .concat(".000000"); // in js format like 2021-03-12T19:00:00Z + + console.log("converted", converted); + // like 2021-01-03 15:31:02.918940 + return converted; + } + + testdateconvert() { + let converted = this.convertRssDate("2021-03-12T19:00:00Z"); + console.log("converted", converted); + } + + postgresEventsExisting = []; + writeFile = (fileName, data) => { + // write file to disk + fs.writeFile( + `./sources_examples/${fileName}`, + JSON.stringify(data), + "utf8", + (err) => { + if (err) { + console.log(`Error writing file: ${err}`); + } else { + console.log(`File ${fileName} is written successfully!`); + } + } + ); + }; + osmcal = { + queryToAdd: "", + counterOfEventsToAdd: 0, + doesEventExists: (event) => { + }, + addQuery: (event) => { + + this.agendadulibre.counterOfEventsToAdd++; + this.counterOfEventsToAdd++; + + }, + }; + agendadulibre = { + queryToAdd: "", + counterOfEventsToAdd: 0, + doesEventExists: (event) => { + }, + addQuery: (rssEvent) => { + if (this.agendadulibre.queryToAdd) { + this.agendadulibre.queryToAdd += ` , `; + } + + 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 = "'" + this.convertRssDate(rssEvent.date) + "'"; + let ends_on = "'" + this.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}'; + // 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;