diff --git a/config.ts b/config.ts index 53e7b56..0edea84 100644 --- a/config.ts +++ b/config.ts @@ -7,7 +7,7 @@ const parserConfig = { // mobilizon instance feeder_mobilizon_user_id: "3", // organizer_actor_id pour rattacher les nouveaux évènements à un utilisateur. 3 est le premier admin créé. mobilizon_public_url: "https://mobilizon.openstreetmap.fr", // url publique de l'instance mobilizon pour créer les url d'évènements - dev_url: "http://localhost:4000/api", // url publique de l'instance mobilizon pour créer les url d'évènements + dev_url: "http://127.0.0.1:4000/api", // url publique de l'instance mobilizon pour créer les url d'évènements // database of mobilizon db_name: "mobilizon_dev", db_user: "mobilizon", @@ -18,7 +18,11 @@ const parserConfig = { runAddQueriesToMobilizonBDD: false, 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 + runAddQueriesToMobilizonAPI: true, + enableFetch: true, + dev_mode: true, + bearer_token: "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJtb2JpbGl6b24iLCJleHAiOjE2NDE4MTM2NjYsImlhdCI6MTY0MTgxMjc2NiwiaXNzIjoibW9iaWxpem9uIiwianRpIjoiOWUwM2IwMWQtZTE1Ni00Mjk3LWFlNWYtNjAwZTI5OTlmYzY2IiwibmJmIjoxNjQxODEyNzY1LCJzdWIiOiJVc2VyOjEiLCJ0eXAiOiJhY2Nlc3MifQ.5n5_BfxwiMBQHu7X1DBHpyWV9voKLmmq6Pr-1VaUj-wwYZPwFmIl0S09EGqEITpERBPqDiKw8TmmHJ5gzhZPbQ" + }; export default parserConfig; diff --git a/index.ts b/index.ts index 2cfc3fd..c0502e3 100644 --- a/index.ts +++ b/index.ts @@ -68,7 +68,7 @@ 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(eventFound.title); // console.log('item', item) utilsTools.agendadulibre.doesEventExists(eventFound); }); @@ -112,26 +112,35 @@ async function init() { utilsTools.agendadulibre.queryToAdd.forEach((graphQLquery: any) => { - if (limiter && !counter) { + if (limiter && counter<1) { counter++; - console.log('graphQLquery.variables.title', graphQLquery.variables.title); + console.log(counter,' * ', graphQLquery.variables.title); const body = { operationName: "createEvent", query: graphQLquery.query, variables: graphQLquery.variables } - // fetch(parserConfig.dev_url, { - // method: "post", - // body: JSON.stringify(body), - // headers: {"Content-Type": "application/json"} - // }) - // .then(res => { - // res.json() - // console.log('succès'); - // }) - // .then(json => console.log(json)) - // .catch(err => console.log(err)) + + 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, + } + }) + .then((res:any) => { + res.json() + console.log('succès'); + }) + .then((json:any) => console.log(json)) + .catch((err:any) => console.log(err)) + }else{ + console.log('---- le fetch est désactivé'); + } + } diff --git a/utils.ts b/utils.ts index de9be98..3cc1a5d 100644 --- a/utils.ts +++ b/utils.ts @@ -206,19 +206,20 @@ class utils { return false; }, addQuery: (event: any) => { + console.log('event', event); this.agendadulibre.queryToAdd.push( { operationName: "createEvent", query: "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", variables: { attributedToId: null, - beginsOn: event.date_start, + beginsOn: event.date, contacts: [], description: "

"+event.content+"

", draft: false, - endsOn: event.date_end, + endsOn: event.date, joinOptions: "FREE", - onlineAddress: "https://cipherbliss.com", + onlineAddress: event.link, options: { anonymousParticipation: true, attendees: [],