feat(journeesmondiales) include event description in feed item body
This commit is contained in:
parent
4e508f419b
commit
4cfa80e9fc
@ -1,17 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
// Require necessary libraries
|
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
// Configuration
|
|
||||||
$eventsUrl = "https://www.journee-mondiale.com/les-journees-mondiales.htm";
|
$eventsUrl = "https://www.journee-mondiale.com/les-journees-mondiales.htm";
|
||||||
$outputFile = "/app/data/public/daily_events_rss.xml";
|
$outputFile = "/app/data/public/daily_events_rss.xml";
|
||||||
$timezone = "Europe/Brussels";
|
$timezone = "Europe/Brussels";
|
||||||
date_default_timezone_set($timezone);
|
date_default_timezone_set($timezone);
|
||||||
|
|
||||||
// Create output directory if it doesn't exist
|
|
||||||
@mkdir(dirname($outputFile), 0777, true);
|
@mkdir(dirname($outputFile), 0777, true);
|
||||||
|
|
||||||
// Translate month names from English to French
|
|
||||||
$monthsTranslation = [
|
$monthsTranslation = [
|
||||||
'January' => 'janvier', 'February' => 'février', 'March' => 'mars',
|
'January' => 'janvier', 'February' => 'février', 'March' => 'mars',
|
||||||
'April' => 'avril', 'May' => 'mai', 'June' => 'juin', 'July' => 'juillet',
|
'April' => 'avril', 'May' => 'mai', 'June' => 'juin', 'July' => 'juillet',
|
||||||
@ -19,18 +15,14 @@ $monthsTranslation = [
|
|||||||
'November' => 'novembre', 'December' => 'décembre'
|
'November' => 'novembre', 'December' => 'décembre'
|
||||||
];
|
];
|
||||||
|
|
||||||
// Get today's date in French
|
|
||||||
$currentDate = date("j F");
|
$currentDate = date("j F");
|
||||||
$currentDateParts = explode(' ', $currentDate);
|
$currentDateParts = explode(' ', $currentDate);
|
||||||
$currentDay = $currentDateParts[0];
|
$currentDay = $currentDateParts[0];
|
||||||
$currentMonth = $monthsTranslation[$currentDateParts[1]] ?? $currentDateParts[1];
|
$currentMonth = $monthsTranslation[$currentDateParts[1]] ?? $currentDateParts[1];
|
||||||
$currentDateFr = $currentDay . ' ' . $currentMonth;
|
$currentDateFr = $currentDay . ' ' . $currentMonth;
|
||||||
|
|
||||||
// Fetch and parse events from the webpage
|
|
||||||
$html = file_get_contents($eventsUrl);
|
$html = file_get_contents($eventsUrl);
|
||||||
if (!$html) {
|
if (!$html) die;
|
||||||
die("Erreur : Impossible de récupérer les événements depuis $eventsUrl");
|
|
||||||
}
|
|
||||||
|
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
'/<li[^>]*><a href="([^"]+)"[^>]*><time datetime="([^"]+)"[^>]*>([^<]+)<\/time> : ([^<]+)<\/a><\/li>/',
|
'/<li[^>]*><a href="([^"]+)"[^>]*><time datetime="([^"]+)"[^>]*>([^<]+)<\/time> : ([^<]+)<\/a><\/li>/',
|
||||||
@ -39,15 +31,9 @@ preg_match_all(
|
|||||||
PREG_SET_ORDER
|
PREG_SET_ORDER
|
||||||
);
|
);
|
||||||
|
|
||||||
if (empty($matches)) {
|
|
||||||
die("Erreur : Aucun événement trouvé dans le contenu HTML.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract and filter events for today
|
|
||||||
$events = array_filter(array_map(function ($match) use ($currentDateFr) {
|
$events = array_filter(array_map(function ($match) use ($currentDateFr) {
|
||||||
$eventDate = str_replace(["\xc2\xa0", "1 "], [" ", "1er "], mb_strtolower(trim($match[2])));
|
$eventDate = str_replace(["\xc2\xa0", "1 "], [" ", "1er "], mb_strtolower(trim($match[2])));
|
||||||
$currentDateNormalized = str_replace("\xc2\xa0", " ", mb_strtolower($currentDateFr));
|
$currentDateNormalized = str_replace("\xc2\xa0", " ", mb_strtolower($currentDateFr));
|
||||||
|
|
||||||
return $eventDate === $currentDateNormalized ? [
|
return $eventDate === $currentDateNormalized ? [
|
||||||
"url" => htmlspecialchars($match[1]),
|
"url" => htmlspecialchars($match[1]),
|
||||||
"date" => htmlspecialchars($match[2]),
|
"date" => htmlspecialchars($match[2]),
|
||||||
@ -55,12 +41,21 @@ $events = array_filter(array_map(function ($match) use ($currentDateFr) {
|
|||||||
] : null;
|
] : null;
|
||||||
}, $matches));
|
}, $matches));
|
||||||
|
|
||||||
if (empty($events)) {
|
if (empty($events)) exit;
|
||||||
echo "Aucun événement trouvé pour aujourd'hui ($currentDateFr).\n";
|
|
||||||
exit;
|
function fetchEventContent($url) {
|
||||||
|
$contentHtml = file_get_contents($url);
|
||||||
|
if (!$contentHtml) return null;
|
||||||
|
|
||||||
|
preg_match(
|
||||||
|
'/<section[^>]*itemprop="description"[^>]*>(.*?)<\/section>/s',
|
||||||
|
$contentHtml,
|
||||||
|
$contentMatch
|
||||||
|
);
|
||||||
|
|
||||||
|
return $contentMatch[1] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate RSS feed
|
|
||||||
$rss = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"></rss>');
|
$rss = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"></rss>');
|
||||||
$channel = $rss->addChild('channel');
|
$channel = $rss->addChild('channel');
|
||||||
$channel->addChild('title', "Flux RSS des journées mondiales");
|
$channel->addChild('title', "Flux RSS des journées mondiales");
|
||||||
@ -70,14 +65,14 @@ $channel->addChild('language', 'fr');
|
|||||||
$channel->addChild('pubDate', date(DATE_RSS));
|
$channel->addChild('pubDate', date(DATE_RSS));
|
||||||
|
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
|
$content = fetchEventContent($event['url']);
|
||||||
$item = $channel->addChild('item');
|
$item = $channel->addChild('item');
|
||||||
$item->addChild('title', $event['event']);
|
$item->addChild('title', $event['event']);
|
||||||
$item->addChild('link', $event['url']);
|
$item->addChild('link', $event['url']);
|
||||||
$item->addChild('guid', $event['url']);
|
$item->addChild('guid', $event['url']);
|
||||||
$item->addChild('pubDate', date(DATE_RSS));
|
$item->addChild('pubDate', date(DATE_RSS));
|
||||||
|
$item->addChild('description', $content ? htmlspecialchars($content) : "Description indisponible.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save RSS feed to file
|
|
||||||
$rss->asXML($outputFile);
|
$rss->asXML($outputFile);
|
||||||
|
|
||||||
echo "Flux RSS généré à $outputFile avec " . count($events) . " événements pour aujourd'hui.\n";
|
echo "Flux RSS généré à $outputFile avec " . count($events) . " événements pour aujourd'hui.\n";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user