multi import events in conf

This commit is contained in:
Tykayn 2022-01-10 12:48:37 +01:00 committed by tykayn
parent e584fcf61d
commit b9a874b7ac
4 changed files with 228 additions and 215 deletions

View File

@ -19,9 +19,11 @@ const parserConfig = {
debug: false, debug: false,
organizerActorId: 3, // ID of the user who imports events in the mobilizon instance. 3 is the first admin user created, usually. organizerActorId: 3, // ID of the user who imports events in the mobilizon instance. 3 is the first admin user created, usually.
runAddQueriesToMobilizonAPI: true, runAddQueriesToMobilizonAPI: true,
enableFetch: true, enableFetch: true, // enable persisting of new events via API
dev_mode: true, dev_mode: true, // dev mode uses localhost instance of mobilizon running on port 4000
bearer_token: "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJtb2JpbGl6b24iLCJleHAiOjE2NDE4MTM2NjYsImlhdCI6MTY0MTgxMjc2NiwiaXNzIjoibW9iaWxpem9uIiwianRpIjoiOWUwM2IwMWQtZTE1Ni00Mjk3LWFlNWYtNjAwZTI5OTlmYzY2IiwibmJmIjoxNjQxODEyNzY1LCJzdWIiOiJVc2VyOjEiLCJ0eXAiOiJhY2Nlc3MifQ.5n5_BfxwiMBQHu7X1DBHpyWV9voKLmmq6Pr-1VaUj-wwYZPwFmIl0S09EGqEITpERBPqDiKw8TmmHJ5gzhZPbQ" limit_persistence_of_new_events:true,
max_new_events: 1,
bearer_token: "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJtb2JpbGl6b24iLCJleHAiOjE2NDE4MTU0MDMsImlhdCI6MTY0MTgxNDUwMywiaXNzIjoibW9iaWxpem9uIiwianRpIjoiNTU0ZGRlY2YtZDNjMS00NzcwLWJkODAtMTAwMjM3ZjkwYmU2IiwibmJmIjoxNjQxODE0NTAyLCJzdWIiOiJVc2VyOjEiLCJ0eXAiOiJhY2Nlc3MifQ._tFmxJTIBY01vhv9Sj5uADIC_5pP6kx3xdgUgefS36r-lrOZlLeKvD0DpDPh4DM3-lkTonPtZlGRcIyr0I5DpQ"
}; };

View File

@ -39,9 +39,13 @@ async function init() {
console.log('✅ OK connecté à postgresql'); console.log('✅ OK connecté à postgresql');
console.log(' '); console.log(' ');
const res = await utilsTools.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! console.log('💾 évènements enregistrés dans mobilizon : ', res.rows.length);
// console.log('res', res); // console.log('res', res);
utilsTools.localMobilizonEventsByTitle = res.rows; res.rows.forEach((elem: any) => {
// console.log('elem', elem.title);
utilsTools.localMobilizonEventsByTitle.push(elem.title);
})
if (parserConfig.askAgendaDuLibre) { if (parserConfig.askAgendaDuLibre) {
// @ts-ignore // @ts-ignore
@ -68,8 +72,6 @@ async function init() {
'⌛ 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) => { feed.items.forEach((eventFound) => {
// console.log(eventFound.title);
// console.log('item', item)
utilsTools.agendadulibre.doesEventExists(eventFound); utilsTools.agendadulibre.doesEventExists(eventFound);
}); });
} }
@ -106,15 +108,16 @@ async function init() {
' rajouter les évènements manquants par l\'API GraphQL', ' rajouter les évènements manquants par l\'API GraphQL',
utilsTools.agendadulibre.queryToAdd.length utilsTools.agendadulibre.queryToAdd.length
); );
let limiter = true; let limiter = parserConfig.limit_persistence_of_new_events;
let counter = 0; let counter = 0;
let bearerTokenIsOK = true;
utilsTools.agendadulibre.queryToAdd.forEach((graphQLquery: any) => { utilsTools.agendadulibre.queryToAdd.forEach((graphQLquery: any) => {
if (limiter && counter<1) { if (limiter && counter <= parserConfig.max_new_events && bearerTokenIsOK) {
counter++; counter++;
console.log(counter,' * ', graphQLquery.variables.title); console.log(counter, ' * ', graphQLquery.variables.title);
const body = { const body = {
operationName: "createEvent", operationName: "createEvent",
@ -122,22 +125,30 @@ async function init() {
variables: graphQLquery.variables variables: graphQLquery.variables
} }
if(parserConfig.enableFetch){ if (parserConfig.enableFetch) {
fetch(parserConfig.dev_mode? parserConfig.dev_url : parserConfig.mobilizon_public_url, { fetch(parserConfig.dev_mode ? parserConfig.dev_url : parserConfig.mobilizon_public_url, {
method: "post", method: "post",
body: JSON.stringify(body), body: JSON.stringify(body),
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"authorization": "Bearer "+parserConfig.bearer_token, "authorization": "Bearer " + parserConfig.bearer_token,
} }
}) })
.then((res:any) => { .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() res.json()
console.log('succès');
}) })
.then((json:any) => console.log(json)) .then((json: any) => console.log(json))
.catch((err:any) => console.log(err)) .catch((err: any) => console.log(err))
}else{ } else {
console.log('---- le fetch est désactivé'); console.log('---- le fetch est désactivé');
} }
@ -158,6 +169,7 @@ async function init() {
}); });
} }
// @ts-ignore // @ts-ignore
console.log(' ---------- '.green); console.log(' ---------- '.green);
// @ts-ignore // @ts-ignore

File diff suppressed because one or more lines are too long

View File

@ -163,7 +163,6 @@ class utils {
} }
console.log(' ') console.log(' ')
console.log(' title', title) console.log(' title', title)
console.log(' content', content)
let uuid = uuidv4(); let uuid = uuidv4();
let uuidString = "'" + uuid + "'"; let uuidString = "'" + uuid + "'";
@ -206,7 +205,7 @@ class utils {
return false; return false;
}, },
addQuery: (event: any) => { addQuery: (event: any) => {
console.log('event', event); console.log('event', event.title);
this.agendadulibre.queryToAdd.push( this.agendadulibre.queryToAdd.push(
{ {
operationName: "createEvent", operationName: "createEvent",