multi import events in conf
This commit is contained in:
parent
e584fcf61d
commit
b9a874b7ac
@ -19,9 +19,11 @@ const parserConfig = {
|
||||
debug: false,
|
||||
organizerActorId: 3, // ID of the user who imports events in the mobilizon instance. 3 is the first admin user created, usually.
|
||||
runAddQueriesToMobilizonAPI: true,
|
||||
enableFetch: true,
|
||||
dev_mode: true,
|
||||
bearer_token: "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJtb2JpbGl6b24iLCJleHAiOjE2NDE4MTM2NjYsImlhdCI6MTY0MTgxMjc2NiwiaXNzIjoibW9iaWxpem9uIiwianRpIjoiOWUwM2IwMWQtZTE1Ni00Mjk3LWFlNWYtNjAwZTI5OTlmYzY2IiwibmJmIjoxNjQxODEyNzY1LCJzdWIiOiJVc2VyOjEiLCJ0eXAiOiJhY2Nlc3MifQ.5n5_BfxwiMBQHu7X1DBHpyWV9voKLmmq6Pr-1VaUj-wwYZPwFmIl0S09EGqEITpERBPqDiKw8TmmHJ5gzhZPbQ"
|
||||
enableFetch: true, // enable persisting of new events via API
|
||||
dev_mode: true, // dev mode uses localhost instance of mobilizon running on port 4000
|
||||
limit_persistence_of_new_events:true,
|
||||
max_new_events: 1,
|
||||
bearer_token: "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJtb2JpbGl6b24iLCJleHAiOjE2NDE4MTU0MDMsImlhdCI6MTY0MTgxNDUwMywiaXNzIjoibW9iaWxpem9uIiwianRpIjoiNTU0ZGRlY2YtZDNjMS00NzcwLWJkODAtMTAwMjM3ZjkwYmU2IiwibmJmIjoxNjQxODE0NTAyLCJzdWIiOiJVc2VyOjEiLCJ0eXAiOiJhY2Nlc3MifQ._tFmxJTIBY01vhv9Sj5uADIC_5pP6kx3xdgUgefS36r-lrOZlLeKvD0DpDPh4DM3-lkTonPtZlGRcIyr0I5DpQ"
|
||||
|
||||
|
||||
};
|
||||
|
44
index.ts
44
index.ts
@ -39,9 +39,13 @@ async function init() {
|
||||
console.log('✅ OK connecté à postgresql');
|
||||
console.log(' ');
|
||||
const res = await utilsTools.client.query('SELECT * from events');
|
||||
console.log('💾 évènements enregistrés dans mobilizon : ', res.rows.length); // Hello world!
|
||||
console.log('💾 évènements enregistrés dans mobilizon : ', res.rows.length);
|
||||
// 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) {
|
||||
// @ts-ignore
|
||||
@ -68,8 +72,6 @@ async function init() {
|
||||
'⌛ trouver les évènements qui ne font pas partie de la BDD mobilizon postgresql',
|
||||
);
|
||||
feed.items.forEach((eventFound) => {
|
||||
// console.log(eventFound.title);
|
||||
// console.log('item', item)
|
||||
utilsTools.agendadulibre.doesEventExists(eventFound);
|
||||
});
|
||||
}
|
||||
@ -106,15 +108,16 @@ async function init() {
|
||||
'➕ rajouter les évènements manquants par l\'API GraphQL',
|
||||
utilsTools.agendadulibre.queryToAdd.length
|
||||
);
|
||||
let limiter = true;
|
||||
let limiter = parserConfig.limit_persistence_of_new_events;
|
||||
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++;
|
||||
console.log(counter,' * ', graphQLquery.variables.title);
|
||||
console.log(counter, ' * ', graphQLquery.variables.title);
|
||||
|
||||
const body = {
|
||||
operationName: "createEvent",
|
||||
@ -122,22 +125,30 @@ async function init() {
|
||||
variables: graphQLquery.variables
|
||||
}
|
||||
|
||||
if(parserConfig.enableFetch){
|
||||
fetch(parserConfig.dev_mode? parserConfig.dev_url : parserConfig.mobilizon_public_url, {
|
||||
if (parserConfig.enableFetch) {
|
||||
fetch(parserConfig.dev_mode ? parserConfig.dev_url : parserConfig.mobilizon_public_url, {
|
||||
method: "post",
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"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()
|
||||
console.log('succès');
|
||||
})
|
||||
.then((json:any) => console.log(json))
|
||||
.catch((err:any) => console.log(err))
|
||||
}else{
|
||||
.then((json: any) => console.log(json))
|
||||
.catch((err: any) => console.log(err))
|
||||
} else {
|
||||
console.log('---- le fetch est désactivé');
|
||||
}
|
||||
|
||||
@ -158,6 +169,7 @@ async function init() {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
console.log(' ---------- '.green);
|
||||
// @ts-ignore
|
||||
|
File diff suppressed because one or more lines are too long
3
utils.ts
3
utils.ts
@ -163,7 +163,6 @@ class utils {
|
||||
}
|
||||
console.log(' ')
|
||||
console.log(' title', title)
|
||||
console.log(' content', content)
|
||||
|
||||
let uuid = uuidv4();
|
||||
let uuidString = "'" + uuid + "'";
|
||||
@ -206,7 +205,7 @@ class utils {
|
||||
return false;
|
||||
},
|
||||
addQuery: (event: any) => {
|
||||
console.log('event', event);
|
||||
console.log('event', event.title);
|
||||
this.agendadulibre.queryToAdd.push(
|
||||
{
|
||||
operationName: "createEvent",
|
||||
|
Loading…
Reference in New Issue
Block a user