From ae33a57bf4a8e57a87fa3f6d8e74d4aeb349e1ea Mon Sep 17 00:00:00 2001 From: Tykayn Date: Fri, 3 Mar 2023 19:16:59 +0100 Subject: [PATCH] add agenda du libre IDF events --- helpers/floss_idf.mjs | 10 ++++------ helpers/utils.mjs | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/helpers/floss_idf.mjs b/helpers/floss_idf.mjs index b107701..8f96fee 100644 --- a/helpers/floss_idf.mjs +++ b/helpers/floss_idf.mjs @@ -34,14 +34,15 @@ function makeTitleContentFromAgendaDulibre(articles) { let eventUrl = event.url.replace('.json', '') - content += `\n* [${event.title}](${eventUrl})` ; + // content += `\n* [${event.title}](${eventUrl})` ; + content += `\n* [${event.city} - ${event.title}](${eventUrl})` ; content += `\n* ${tags}` ; - content += `\n* ${event.city} - ${event.title}` ; let start = moment(new Date(event.start_time)).format(event_date_format) let end = moment(new Date(event.end_time)).format(event_date_format) content += `\n ${start} -- ${end}` ; }) + content += `\n`; }) return content; @@ -73,7 +74,4 @@ async function postLink() { sendPostMastodon(configPost) } -// postLink(); - -let difftest = diffDaysBetweenTwoDates(new Date("2023-03-04T14:30:00.000Z") ,new Date()) -console.log('new Date("2023-03-04") ', difftest ) \ No newline at end of file +postLink(); diff --git a/helpers/utils.mjs b/helpers/utils.mjs index 2d8ac52..67d5044 100644 --- a/helpers/utils.mjs +++ b/helpers/utils.mjs @@ -63,8 +63,8 @@ export default function sendPostMastodon(config) { if (!config.reallySendPost) { console.log("\n\n =========== le message ne sera PAS réellement posté sur le compte @" + config.author + "@" + process.env.INSTANCE_MASTODON + " =========== \n") - console.log('configPost.folder_image', config.folder_image) - console.log('config', config) + // console.log('configPost.folder_image', config.folder_image) + console.log('config', config.message) } else { console.log(" ") @@ -420,17 +420,18 @@ export function getArticlesFromDaysInJson(json_content,nbOfDays){ let selectedEvents = []; console.log('getArticlesFromDaysInJson: filtre nbOfDays', nbOfDays) + console.log('events ', json_content.length) json_content.forEach((item) => { let differenceDays = diffDaysBetweenTwoDates(new Date(item.start_time) ,today); - console.log('differenceDays', differenceDays) - if( differenceDays <= nbOfDays || differenceDays == 0 || differenceDays == 1){ - console.log('on garde', item.title) + if( differenceDays < nbOfDays){ + console.log('on garde', differenceDays,item.city, item.title) selectedEvents.push(item) - }else{ - console.log('on ne garde pas', differenceDays) } + // else{ + // console.log('on ne garde pas', differenceDays,item.city, item.title) + // } }) return selectedEvents @@ -438,9 +439,9 @@ export function getArticlesFromDaysInJson(json_content,nbOfDays){ export function diffDaysBetweenTwoDates(date1,date2) { - const diffTime = Math.abs(date2 - date1); - const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); - return diffDays; + const a = moment(date1); + const b = moment(date2); + return a.diff(b, 'days'); } @@ -455,6 +456,7 @@ export function filterRegionAgendaDuLibreEvents(events_list, filter_critera) { }) return selection; } + moment.locale('fr'); export function groupEventsByDay(events_list){ @@ -465,9 +467,8 @@ export function groupEventsByDay(events_list){ if( ! selection[formattedDay]){ selection[formattedDay] = [] - selection[formattedDay].push(item) } + selection[formattedDay].push(item) }) - console.log('selection', selection) return selection; } \ No newline at end of file