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

54 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-01-11 17:36:04 +01:00
import sendPostMastodon, {randomIntFromInterval} 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'
2023-03-10 13:20:25 +01:00
import moment from "moment";
2023-03-03 17:28:41 +01:00
2023-03-10 13:20:25 +01:00
let event_date_format = 'dddd DD/MM HH:mm'
let event_date_format_end = 'HH:mm'
2023-03-03 17:28:41 +01:00
const days_filter = 7;
function makeTitleContentFromAgendaDulibre(articles) {
let content = '';
2025-01-11 17:36:04 +01:00
if (!articles.length) {
2023-03-03 17:52:10 +01:00
return '- Aucun évènement prévu. T_T'
}
2025-01-11 17:36:04 +01:00
articles.forEach(event => {
2023-03-10 13:20:25 +01:00
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)
2025-01-11 17:36:04 +01:00
let tags = '#' + event.tags.split(' ').join(' #')
content += `\n* [${event.city} : ${start} - ${end} | ${event.title}](${eventUrl}) `;
content += `\n ${tags}`;
2023-03-03 17:28:41 +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")
2023-03-03 17:52:10 +01:00
let events_list = coming_events_json.default;
2023-03-03 17:28:41 +01:00
2025-01-11 17:36:04 +01:00
events_list = getArticlesFromDaysInJson(events_list, days_filter);
2023-03-03 17:28:41 +01:00
let contentOfPost = 'Prochains évènements OpenStreetMap dans les ' + days_filter + ' prochains jours: \n'
2023-03-03 17:52:10 +01:00
+ makeTitleContentFromAgendaDulibre(events_list)
2023-03-03 17:28:41 +01:00
let configPost = {
author: 'curator',
website: 'openstreetmap.fr',
// disable_slugify: true,
slug: "osm_event_picture",
content_type: "text/markdown",
2025-01-11 17:36:04 +01:00
image: `${process.cwd()}/assets/osm_post_${randomIntFromInterval(1, 5)}.jpg`,
2023-03-03 17:28:41 +01:00
message: `# ${contentOfPost}
#agenda #floss #openstreetmap #hebdo`,
}
sendPostMastodon(configPost)
}
2023-03-03 17:52:10 +01:00
postLink();