add place info in description
This commit is contained in:
parent
d09767dd4e
commit
71fecd1961
@ -17,15 +17,15 @@ const parserConfig = {
|
|||||||
askOsmCal: false,
|
askOsmCal: false,
|
||||||
runAddQueriesToMobilizonBDD: false,
|
runAddQueriesToMobilizonBDD: false,
|
||||||
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: 4, // 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, // enable persisting of new events via API
|
enableFetch: true, // enable persisting of new events via API
|
||||||
// enableFetch: false,
|
// enableFetch: false,
|
||||||
dev_mode: true, // dev mode uses localhost instance of mobilizon running on port 4000
|
dev_mode: true, // dev mode uses localhost instance of mobilizon running on port 4000
|
||||||
limit_persistence_of_new_events:true,
|
limit_persistence_of_new_events:true,
|
||||||
max_new_events_in_scrapping: 400,
|
max_new_events_in_scrapping: 400,
|
||||||
max_new_events: 5,
|
max_new_events: 60,
|
||||||
bearer_token: "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJtb2JpbGl6b24iLCJleHAiOjE2NDIwODIzOTgsImlhdCI6MTY0MjA4MTQ5OCwiaXNzIjoibW9iaWxpem9uIiwianRpIjoiYWQyZjMxY2YtMDUxZi00MmY0LWI1ZDYtMzc4ZjZiOTgxY2EwIiwibmJmIjoxNjQyMDgxNDk3LCJzdWIiOiJVc2VyOjEiLCJ0eXAiOiJhY2Nlc3MifQ.U0JnKQFkklxDcWPE4utXwj65mR0N1LyT3qwC2RzOiWjLWyCS_0KMKJPm5uvylZ-lhiPigojfZsuQCekYL0qTHg",
|
bearer_token: "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJtb2JpbGl6b24iLCJleHAiOjE2NDIwODQxMTYsImlhdCI6MTY0MjA4MzIxNiwiaXNzIjoibW9iaWxpem9uIiwianRpIjoiOWRkN2Q5NDUtOWNlMC00Mzk4LTgxOTEtMDgxODk4NWYxZTM4IiwibmJmIjoxNjQyMDgzMjE1LCJzdWIiOiJVc2VyOjEiLCJ0eXAiOiJhY2Nlc3MifQ.PXFYQGUID1VM9cc_C_gNK78qhCIco217B9XN9IAUwHc4sx-FX9y_yrryuAfNwCLXYXfafbVBNMZlMNZ5LnwMcg",
|
||||||
|
|
||||||
ccpl: "https://www.cc-paysdelimours.fr/agenda"
|
ccpl: "https://www.cc-paysdelimours.fr/agenda"
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ async function runImportEvents() {
|
|||||||
// get json file for ADL
|
// get json file for ADL
|
||||||
await fs.readFile(filepath, 'utf8', function (err, data) {
|
await fs.readFile(filepath, 'utf8', function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return console.log(err);
|
return console.log('readFile ERROR', err);
|
||||||
}
|
}
|
||||||
filecontent = JSON.parse(data)
|
filecontent = JSON.parse(data)
|
||||||
filecontent = filecontent.slice(0, parserConfig.max_new_events_in_scrapping)
|
filecontent = filecontent.slice(0, parserConfig.max_new_events_in_scrapping)
|
||||||
@ -64,8 +64,8 @@ async function runImportEvents() {
|
|||||||
console.log('nouveaux évènements à ajouter: ', utilsTools.newEvents.length);
|
console.log('nouveaux évènements à ajouter: ', utilsTools.newEvents.length);
|
||||||
let limiter = parserConfig.limit_persistence_of_new_events;
|
let limiter = parserConfig.limit_persistence_of_new_events;
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
|
let counter_max = parserConfig.max_new_events;
|
||||||
|
|
||||||
console.log('utilsTools.localMobilizonEventsByTitle', utilsTools.localMobilizonEventsByTitle);
|
|
||||||
utilsTools.newEvents.forEach((pair: any) => {
|
utilsTools.newEvents.forEach((pair: any) => {
|
||||||
let graphQLquery = pair.newQuery;
|
let graphQLquery = pair.newQuery;
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ async function runImportEvents() {
|
|||||||
console.log('ajouter');
|
console.log('ajouter');
|
||||||
// add a little delay between creations
|
// add a little delay between creations
|
||||||
|
|
||||||
fetchEvent(url, options, counter, pair.event)
|
fetchEvent(url, options, counter, counter_max, pair.event)
|
||||||
} else {
|
} else {
|
||||||
console.log('nope');
|
console.log('nope');
|
||||||
}
|
}
|
||||||
@ -108,10 +108,13 @@ async function runImportEvents() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
let timeout;
|
||||||
const fetchEvent = (theUrl, theOptions, counter, event) => {
|
const fetchEvent = (theUrl, theOptions, counter, counter_max, event) => {
|
||||||
let timeout = setTimeout(
|
let BearerIsOK = true;
|
||||||
|
timeout = setTimeout(
|
||||||
function () {
|
function () {
|
||||||
|
console.log(counter,'/', counter_max,' fetch start - ' + event.title + ' ' + event.start_time);
|
||||||
|
if(BearerIsOK){
|
||||||
|
|
||||||
fetch(theUrl, theOptions)
|
fetch(theUrl, theOptions)
|
||||||
.then((res: any) => {
|
.then((res: any) => {
|
||||||
@ -119,32 +122,29 @@ const fetchEvent = (theUrl, theOptions, counter, event) => {
|
|||||||
console.log(' status', status);
|
console.log(' status', status);
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
console.error(' /!\\ ------------------ ERROR: Bearer token invalid ------------------')
|
console.error(' /!\\ ------------------ ERROR: Bearer token invalid ------------------')
|
||||||
|
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|
||||||
} else if (status === 200) {
|
} else if (status === 200) {
|
||||||
console.log(' succès - ' + event.title + ' ' + event.start_time);
|
console.log(' succès - ' + event.title + ' ' + event.start_time);
|
||||||
|
|
||||||
}
|
}
|
||||||
res.json()
|
// console.log(' res', res);
|
||||||
|
return res.json()
|
||||||
})
|
})
|
||||||
.then((json: any) => console.log(json))
|
.then((json: any) => console.log(counter,'/', counter_max, 'DONE'))
|
||||||
.catch((err: any) => console.log(err))
|
.catch((err: any) => {
|
||||||
|
console.log(err)
|
||||||
|
BearerIsOK = false;
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}.bind(this)
|
||||||
,
|
,
|
||||||
1000 * counter
|
1000 * counter
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fs.stat(filepath, function (err, stat) {
|
|
||||||
// if (err == null) {
|
|
||||||
runImportEvents();
|
runImportEvents();
|
||||||
// } else if (err.code === 'ENOENT') {
|
|
||||||
// // file does not exist
|
|
||||||
// console.log('Scrapped json file does not exist. Run a scraper like "ts-node scrapers/adl.ts" before using this importer: ', err.code);
|
|
||||||
// } else {
|
|
||||||
// console.log('Some other error: ', err.code);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
|
14
utils.ts
14
utils.ts
@ -239,16 +239,16 @@ class utils {
|
|||||||
variables: {
|
variables: {
|
||||||
attributedToId: null,
|
attributedToId: null,
|
||||||
beginsOn: event.start_time,
|
beginsOn: event.start_time,
|
||||||
contacts: [event.contact],
|
contacts: [],
|
||||||
description:
|
description:
|
||||||
|
|
||||||
"<address>" + event.city
|
"<address>" +
|
||||||
+ "<br/>"+
|
"<span class='city'>"+ event.city+"</span><br/>"+
|
||||||
event.address +
|
"<span class='address'>"+ event.address+"</span><br/>"+
|
||||||
"<br/>"+
|
"<span class='place_name'>"+ event.place_name+"</span><br/>"+
|
||||||
event.place_name +
|
|
||||||
"</address>"+
|
"</address>"+
|
||||||
"<p>" + event.description + "</p>",
|
"<span class='contact'>"+ event.contact+"</span><br/>"+
|
||||||
|
"<p class='event_description'>" + event.description + "</p>",
|
||||||
draft: false,
|
draft: false,
|
||||||
endsOn: event.end_time,
|
endsOn: event.end_time,
|
||||||
joinOptions: "FREE",
|
joinOptions: "FREE",
|
||||||
|
Loading…
Reference in New Issue
Block a user