multi-account-post-schedule.../helpers/floss_idf.mjs

75 lines
2.4 KiB
JavaScript
Raw Normal View History

2023-03-03 18:54:50 +01:00
import * as coming_events_json from './../assets/documents/idf_agendadulibre_coming.json' assert { type: "json" } ;
2023-03-10 11:20:37 +01:00
import sendPostMastodon, { filterRegionAgendaDuLibreEvents, groupEventsByDay} from "./libs/utils.mjs";
2023-03-03 18:54:50 +01:00
import moment from 'moment';
2023-03-10 11:20:37 +01:00
import {getArticlesFromDaysInJson} from "./libs/rss_management.mjs";
2023-03-03 18:54:50 +01:00
2023-03-10 10:40:43 +01:00
let event_date_format = 'HH:mm'
2023-03-03 18:54:50 +01:00
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', '')
2023-03-10 10:40:43 +01:00
let start = moment(new Date(event.start_time)).utcOffset(0).format(event_date_format)
let end = moment(new Date(event.end_time)).utcOffset(0).format(event_date_format)
2023-03-03 18:54:50 +01:00
2023-03-03 19:16:59 +01:00
// content += `\n* [${event.title}](${eventUrl})` ;
2023-03-10 10:40:43 +01:00
content += `\n* [${event.city} ${start} - ${end} | ${event.title}](${eventUrl})` ;
content += `\n ${tags}` ;
content += `\n ` ;
2023-03-03 18:54:50 +01:00
})
2023-03-03 19:16:59 +01:00
content += `\n`;
2023-03-03 18:54:50 +01:00
})
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)
}
2023-03-03 19:16:59 +01:00
postLink();