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

56 lines
1.8 KiB
JavaScript

import sendPostMastodon from "./libs/utils.mjs";
import * as coming_events_json from './../assets/documents/agendadulibre_openstreetmap.json' assert { type: "json" };
import {getArticlesFromDaysInJson} from './libs/rss_management.mjs'
import moment from "moment";
let event_date_format = 'dddd DD/MM HH:mm'
let event_date_format_end = 'HH:mm'
const days_filter = 7;
function makeTitleContentFromAgendaDulibre(articles) {
let content = '';
if(! articles.length ){
return '- Aucun évènement prévu. T_T'
}
articles.forEach(event=>{
let eventUrl = event.url.replace('.json', '')
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_end)
let tags = '#'+event.tags.split(' ').join(' #')
content += `\n* [${event.city} : ${start} - ${end} | ${event.title}](${eventUrl})` ;
content += `\n ${tags}` ;
})
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 = getArticlesFromDaysInJson(events_list,days_filter);
let contentOfPost = 'Prochains évènements OpenStreetMap dans les ' + days_filter + ' prochains jours: \n'
+ makeTitleContentFromAgendaDulibre(events_list)
let configPost = {
author: 'curator',
website: 'openstreetmap.fr',
// disable_slugify: true,
slug: "osm_event_picture",
content_type: "text/markdown",
folder_image: process.cwd() + '/assets/',
image: "osm_default.jpg",
message: `# ${contentOfPost}
#agenda #floss #openstreetmap #hebdo`,
}
sendPostMastodon(configPost)
}
postLink();