add politis

This commit is contained in:
quenousimporte 2024-09-04 17:43:51 +02:00
parent 67dc9411e4
commit f5cc7bdb86
1 changed files with 70 additions and 0 deletions

View File

@ -397,6 +397,71 @@
write_epub($epub);
}
// Politis RSS
if (isset($_POST['politis']) && $_POST['politis'])
{
$issuenb = '';
if (isset($_POST['politisnb']))
{
$issuenb = $_POST['politisnb'];
}
$feedurl = 'https://www.politis.fr/flux-rss-politis-fr/';
$opts = [
'http' => [
'method' => "GET",
//'header' => "Accept-language: en\nCookie: MPSESSID=" . $mp_sessionid, // todo
]
];
$context = stream_context_create($opts);
// todo add cover!
$epub = new TPEpubCreator();
$epub->temp_folder = 'temp/';
$epub->epub_file = 'epub/politis' . $issuenb . '.epub';
$epub->title = 'Politis ' . $issuenb . ' - RSS ' . $today;
// load feeds
$feed = file_get_contents($feedurl);
$xml = new SimpleXMLElement($feed);
$items = $xml->xpath("/rss/channel/item");
// reverse to respect timing
foreach (array_reverse($items) as $item)
{
$url = $item->link;
$article = file_get_contents($url, false, $context);
if ($issuenb && !str_contains($article, ' dans lhebdo N° ' . $issuenb))
{
continue;
}
$doc = new DOMDocument();
$doc->loadHTML($article);
$finder = new DomXPath($doc);
$title = $finder->query('//h1')->item(0)->textContent;
$author = $finder->query('//span[@class="nom"]')->item(0)->textContent;
$date = $finder->query('//span[@class="date"]')->item(0)->textContent;
$summary = $finder->query('//div[@class="extrait"]')->item(0)->textContent;
$result = '<h1>' . $title . '</h1>';
$result .= '<p>' . $author . '</p>';
$result .= '<p>' . $date . '</p>';
$result .= '<p><b>' . $summary . '</b></p>';
$nodes = $finder->query('//div[@id="content"]');
$node = $nodes->item(0);
$nodehtml = get_clean_html($node);
$result .= $nodehtml;
$epub->AddPage($result, false, $title);
}
write_epub($epub);
}
// Mediapart home page
if (isset($_POST['mphome']) && $_POST['mphome'])
{
@ -591,6 +656,11 @@
<input id="nyttoday" name="nyttoday" type="checkbox">
<label for="nyttoday">From today's paper embedded script</label>
<h2>Politis</h2>
<input id="politis" name="politis" type="checkbox">
<label for="politis">From RSS.</label>
<label for="politisnb">Optional issue number: </label><input id="politisnb" name="politisnb">
<h2>Admin</h2>
<input id="emptycache" name="emptycache" type="checkbox" checked>
<label for="emptycache">Empty cache</label>