|
|
|
@ -3,13 +3,18 @@ import parserConfig from "./config.ts";
|
|
|
|
|
import {v4 as uuidv4} from "uuid";
|
|
|
|
|
import {Client} from "pg";
|
|
|
|
|
import {htmlEscape} from "escape-goat";
|
|
|
|
|
|
|
|
|
|
import fetch from 'node-fetch';
|
|
|
|
|
const moment = require("moment");
|
|
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
let organizerActorId = 3;
|
|
|
|
|
|
|
|
|
|
let createEventQueryMobilizon = "mutation createEvent($organizerActorId: ID!, $attributedToId: ID, $title: String!, $description: String!, $beginsOn: DateTime!, $endsOn: DateTime, $status: EventStatus, $visibility: EventVisibility, $joinOptions: EventJoinOptions, $draft: Boolean, $tags: [String], $picture: MediaInput, $onlineAddress: String, $phoneAddress: String, $category: String, $physicalAddress: AddressInput, $options: EventOptionsInput, $contacts: [Contact]) {\n createEvent(\n organizerActorId: $organizerActorId\n attributedToId: $attributedToId\n title: $title\n description: $description\n beginsOn: $beginsOn\n endsOn: $endsOn\n status: $status\n visibility: $visibility\n joinOptions: $joinOptions\n draft: $draft\n tags: $tags\n picture: $picture\n onlineAddress: $onlineAddress\n phoneAddress: $phoneAddress\n category: $category\n physicalAddress: $physicalAddress\n options: $options\n contacts: $contacts\n ) {\n ...FullEvent\n __typename\n }\n}\n\nfragment FullEvent on Event {\n id\n uuid\n url\n local\n title\n description\n beginsOn\n endsOn\n status\n visibility\n joinOptions\n draft\n picture {\n id\n url\n name\n metadata {\n width\n height\n blurhash\n __typename\n }\n __typename\n }\n publishAt\n onlineAddress\n phoneAddress\n physicalAddress {\n ...AdressFragment\n __typename\n }\n organizerActor {\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n domain\n name\n url\n id\n summary\n __typename\n }\n contacts {\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n name\n summary\n domain\n url\n id\n __typename\n }\n attributedTo {\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n name\n summary\n domain\n url\n id\n __typename\n }\n participantStats {\n going\n notApproved\n participant\n __typename\n }\n tags {\n ...TagFragment\n __typename\n }\n relatedEvents {\n id\n uuid\n title\n beginsOn\n picture {\n id\n url\n name\n metadata {\n width\n height\n blurhash\n __typename\n }\n __typename\n }\n physicalAddress {\n id\n description\n __typename\n }\n organizerActor {\n id\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n domain\n name\n __typename\n }\n __typename\n }\n options {\n ...EventOptions\n __typename\n }\n metadata {\n key\n title\n value\n type\n __typename\n }\n __typename\n}\n\nfragment AdressFragment on Address {\n id\n description\n geom\n street\n locality\n postalCode\n region\n country\n type\n url\n originId\n __typename\n}\n\nfragment TagFragment on Tag {\n id\n slug\n title\n __typename\n}\n\nfragment EventOptions on EventOptions {\n maximumAttendeeCapacity\n remainingAttendeeCapacity\n showRemainingAttendeeCapacity\n anonymousParticipation\n showStartTime\n showEndTime\n offers {\n price\n priceCurrency\n url\n __typename\n }\n participationConditions {\n title\n content\n url\n __typename\n }\n attendees\n program\n commentModeration\n showParticipationPrice\n hideOrganizerWhenGroupEvent\n __typename\n}\n";
|
|
|
|
|
|
|
|
|
|
function proxy_fetch(theUrl: string, theOptions: any) {
|
|
|
|
|
return fetch(theUrl,theOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* utilitaries to manipulate scraped object and prepare queries to import in mobilizon
|
|
|
|
|
*/
|
|
|
|
@ -227,13 +232,11 @@ class utils {
|
|
|
|
|
if (parserConfig.debug) {
|
|
|
|
|
console.log('ajouter l event ', htmlEscape(event.start_date + ' ' + event.title));
|
|
|
|
|
}
|
|
|
|
|
this.agendadulibre.addQuery(event);
|
|
|
|
|
this.agendadulibre.addQueryFromJsonScrap(event);
|
|
|
|
|
}
|
|
|
|
|
return eventAlreadyExists;
|
|
|
|
|
},
|
|
|
|
|
addQueryFromJsonScrap: (event: any) => {
|
|
|
|
|
console.log('event', event.title);
|
|
|
|
|
|
|
|
|
|
this.agendadulibre.queryToAdd.push(
|
|
|
|
|
{
|
|
|
|
|
operationName: "createEvent",
|
|
|
|
@ -262,12 +265,10 @@ class utils {
|
|
|
|
|
showRemainingAttendeeCapacity: false,
|
|
|
|
|
showStartTime: true
|
|
|
|
|
},
|
|
|
|
|
organizerActorId: "3",
|
|
|
|
|
organizerActorId: organizerActorId,
|
|
|
|
|
phoneAddress: "",
|
|
|
|
|
status: "CONFIRMED",
|
|
|
|
|
tags: [
|
|
|
|
|
"osm",
|
|
|
|
|
"openstreetmap",
|
|
|
|
|
"imported"
|
|
|
|
|
],
|
|
|
|
|
title: event.title,
|
|
|
|
@ -308,7 +309,7 @@ class utils {
|
|
|
|
|
showRemainingAttendeeCapacity: false,
|
|
|
|
|
showStartTime: true
|
|
|
|
|
},
|
|
|
|
|
organizerActorId: "3",
|
|
|
|
|
organizerActorId: organizerActorId,
|
|
|
|
|
phoneAddress: "",
|
|
|
|
|
status: "CONFIRMED",
|
|
|
|
|
tags: [
|
|
|
|
@ -324,29 +325,64 @@ class utils {
|
|
|
|
|
|
|
|
|
|
return this.agendadulibre.queryToAdd;
|
|
|
|
|
},
|
|
|
|
|
addQueryBDD: (event: any) => {
|
|
|
|
|
if (this.agendadulibre.queryToAdd) {
|
|
|
|
|
this.agendadulibre.queryToAdd += ` , `;
|
|
|
|
|
}
|
|
|
|
|
addNewEventsFromQueries:()=>{
|
|
|
|
|
|
|
|
|
|
if (parserConfig.runAddQueriesToMobilizonAPI) {
|
|
|
|
|
console.log(
|
|
|
|
|
'➕ rajouter les évènements manquants par l\'API GraphQL',
|
|
|
|
|
this.agendadulibre.queryToAdd.length
|
|
|
|
|
);
|
|
|
|
|
let limiter = parserConfig.limit_persistence_of_new_events;
|
|
|
|
|
let counter = 0;
|
|
|
|
|
let bearerTokenIsOK = true;
|
|
|
|
|
|
|
|
|
|
this.agendadulibre.queryToAdd.forEach((graphQLquery: any) => {
|
|
|
|
|
|
|
|
|
|
if (limiter && counter <= parserConfig.max_new_events && bearerTokenIsOK) {
|
|
|
|
|
counter++;
|
|
|
|
|
console.log(counter, ' * ', graphQLquery.variables.title);
|
|
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
|
operationName: "createEvent",
|
|
|
|
|
query: graphQLquery.query,
|
|
|
|
|
variables: graphQLquery.variables
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parserConfig.enableFetch) {
|
|
|
|
|
let theUrl :string = parserConfig.dev_mode ? parserConfig.dev_url : parserConfig.mobilizon_public_url;
|
|
|
|
|
let theOptions:any = {
|
|
|
|
|
method: "post",
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"authorization": "Bearer " + parserConfig.bearer_token,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
proxy_fetch(theUrl, theOptions)
|
|
|
|
|
.then((res: any) => {
|
|
|
|
|
let status = res.status;
|
|
|
|
|
console.log('status', status);
|
|
|
|
|
if (status === 401) {
|
|
|
|
|
console.error(' /!\\ ------------------ ERROR: Bearer token invalid ------------------')
|
|
|
|
|
bearerTokenIsOK = false;
|
|
|
|
|
} else if (status === 200) {
|
|
|
|
|
console.log('succès');
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
res.json()
|
|
|
|
|
})
|
|
|
|
|
.then((json: any) => console.log(json))
|
|
|
|
|
.catch((err: any) => console.log(err))
|
|
|
|
|
} else {
|
|
|
|
|
console.log('---- le fetch est désactivé');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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++;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|