|
|
|
@ -38,7 +38,7 @@ async function runImportEvents() {
|
|
|
|
|
return console.log(err); |
|
|
|
|
} |
|
|
|
|
filecontent = JSON.parse(data) |
|
|
|
|
filecontent = filecontent.slice(0,parserConfig.max_new_events_in_scrapping) |
|
|
|
|
filecontent = filecontent.slice(0, parserConfig.max_new_events_in_scrapping) |
|
|
|
|
console.log('events in the scrapped json', filecontent.length); |
|
|
|
|
|
|
|
|
|
let ii = 0; |
|
|
|
@ -89,10 +89,12 @@ async function runImportEvents() {
|
|
|
|
|
"authorization": "Bearer " + parserConfig.bearer_token, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(!utilsTools.agendadulibre.doesEventExistsFromJsonScrap(pair.event)){ |
|
|
|
|
if (!utilsTools.agendadulibre.doesEventExistsFromJsonScrap(pair.event)) { |
|
|
|
|
console.log('ajouter'); |
|
|
|
|
fetchEvent(url, options) |
|
|
|
|
}else{ |
|
|
|
|
// add a little delay between creations
|
|
|
|
|
|
|
|
|
|
fetchEvent(url, options, counter, pair.event) |
|
|
|
|
} else { |
|
|
|
|
console.log('nope'); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -107,22 +109,31 @@ async function runImportEvents() {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const fetchEvent = (theUrl, theOptions) => { |
|
|
|
|
fetch(theUrl, theOptions) |
|
|
|
|
.then((res: any) => { |
|
|
|
|
let status = res.status; |
|
|
|
|
console.log('status', status); |
|
|
|
|
if (status === 401) { |
|
|
|
|
console.error(' /!\\ ------------------ ERROR: Bearer token invalid ------------------') |
|
|
|
|
const fetchEvent = (theUrl, theOptions, counter, event) => { |
|
|
|
|
let timeout = setTimeout( |
|
|
|
|
function () { |
|
|
|
|
|
|
|
|
|
} else if (status === 200) { |
|
|
|
|
console.log('succès'); |
|
|
|
|
fetch(theUrl, theOptions) |
|
|
|
|
.then((res: any) => { |
|
|
|
|
let status = res.status; |
|
|
|
|
console.log('status', status); |
|
|
|
|
if (status === 401) { |
|
|
|
|
console.error(' /!\\ ------------------ ERROR: Bearer token invalid ------------------') |
|
|
|
|
clearTimeout(timeout); |
|
|
|
|
|
|
|
|
|
} else if (status === 200) { |
|
|
|
|
console.log('succès - ' + event.title + ' ' + event.start_time); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
res.json() |
|
|
|
|
}) |
|
|
|
|
.then((json: any) => console.log(json)) |
|
|
|
|
.catch((err: any) => console.log(err)) |
|
|
|
|
} |
|
|
|
|
, |
|
|
|
|
1000 * counter |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
res.json() |
|
|
|
|
}) |
|
|
|
|
.then((json: any) => console.log(json)) |
|
|
|
|
.catch((err: any) => console.log(err)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// fs.stat(filepath, function (err, stat) {
|
|
|
|
|