2023-03-03 18:54:50 +01:00
|
|
|
import * as coming_events_json from './../assets/documents/idf_agendadulibre_coming.json' assert { type: "json" } ;
|
|
|
|
import sendPostMastodon, {getArticlesFromDaysInJson, filterRegionAgendaDuLibreEvents, groupEventsByDay} from "./utils.mjs";
|
|
|
|
import moment from 'moment';
|
|
|
|
import {diffDaysBetweenTwoDates} from "./utils.mjs";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let event_date_format = 'hh:mm'
|
|
|
|
const days_filter = 7;
|
|
|
|
|
|
|
|
moment.locale('fr')
|
|
|
|
|
|
|
|
function makeTitleContentFromAgendaDulibre(articles) {
|
|
|
|
|
|
|
|
let content = '';
|
|
|
|
|
|
|
|
if (!articles.length) {
|
|
|
|
return '- Aucun évènement prévu. T_T'
|
|
|
|
}
|
|
|
|
|
|
|
|
articles = groupEventsByDay(articles);
|
|
|
|
|
|
|
|
let sortedDays = Object.keys(articles)
|
|
|
|
|
|
|
|
sortedDays.forEach((dayOfEvents, index) => {
|
|
|
|
// console.log('item', item, articles[item])
|
|
|
|
console.log('item', dayOfEvents)
|
|
|
|
content += `\n## ${dayOfEvents}` ;
|
|
|
|
|
|
|
|
articles[dayOfEvents].forEach(event =>{
|
|
|
|
console.log('event.title', event.title)
|
|
|
|
|
|
|
|
let tags = '#'+event.tags.split(' ').join(' #')
|
|
|
|
let eventUrl = event.url.replace('.json', '')
|
|
|
|
|
|
|
|
|
|
|
|
content += `\n* [${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}` ;
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function postLink() {
|
|
|
|
|
|
|
|
console.log("curator: résumé des prochains évènements de l'agenda du libre en ile de france dans les " + days_filter + " jours")
|
|
|
|
let events_list = coming_events_json.default;
|
|
|
|
|
|
|
|
events_list = filterRegionAgendaDuLibreEvents(events_list, "12");
|
|
|
|
events_list = getArticlesFromDaysInJson(events_list, days_filter);
|
|
|
|
|
|
|
|
let contentOfPost = 'Prochains évènements libristes en île de France dans les ' + days_filter + ' prochains jours: \n'
|
|
|
|
+ makeTitleContentFromAgendaDulibre(events_list)
|
|
|
|
|
|
|
|
let configPost = {
|
|
|
|
author: 'curator',
|
|
|
|
website: 'openstreetmap.fr',
|
|
|
|
slug: "floss_event_picture",
|
|
|
|
content_type: "text/markdown",
|
|
|
|
folder_image: process.cwd() + '/assets/',
|
|
|
|
image: "floss_default.jpg",
|
|
|
|
message: `# ${contentOfPost}
|
|
|
|
|
|
|
|
#agenda #floss #openstreetmap #hebdo`,
|
|
|
|
}
|
|
|
|
sendPostMastodon(configPost)
|
|
|
|
}
|
|
|
|
|
|
|
|
// postLink();
|
|
|
|
|
|
|
|
let difftest = diffDaysBetweenTwoDates(new Date("2023-03-04T14:30:00.000Z") ,new Date())
|
2023-03-03 18:55:05 +01:00
|
|
|
console.log('new Date("2023-03-04") ', difftest )
|