mediapart remove filter by date to get 10 last articles
This commit is contained in:
parent
a5b4b1e735
commit
a7d045b484
|
@ -17,7 +17,7 @@
|
||||||
<h2>Quotidiens</h2>
|
<h2>Quotidiens</h2>
|
||||||
<p>
|
<p>
|
||||||
<a href="https://mediapart.fr">Mediapart</a>
|
<a href="https://mediapart.fr">Mediapart</a>
|
||||||
- <a href="./mediapart.php">Edition du jour en version texte</a><br>
|
- <a href="./mediapart.php">10 derniers articles en version texte</a><br>
|
||||||
<a href="https://lesjours.fr">Les jours</a><br>
|
<a href="https://lesjours.fr">Les jours</a><br>
|
||||||
<a href="https://reporterre.net/">Reporterre</a><br>
|
<a href="https://reporterre.net/">Reporterre</a><br>
|
||||||
<a href="https://basta.media">Basta!</a><br>
|
<a href="https://basta.media">Basta!</a><br>
|
||||||
|
|
|
@ -23,56 +23,54 @@ $result = '';
|
||||||
|
|
||||||
foreach ($items as $item)
|
foreach ($items as $item)
|
||||||
{
|
{
|
||||||
if (str_starts_with($item->pubDate, date("D, j M Y")))
|
$title = $item->title;
|
||||||
{
|
//$category = $item->category;
|
||||||
$title = $item->title;
|
$category = $item->xpath('dc:subject')[0];
|
||||||
//$category = $item->category;
|
$author = $item->xpath('dc:creator')[0];
|
||||||
$category = $item->xpath('dc:subject')[0];
|
$summary = $item->description;
|
||||||
$author = $item->xpath('dc:creator')[0];
|
|
||||||
$summary = $item->description;
|
|
||||||
|
|
||||||
// Add to content
|
|
||||||
$header .= '- ' . $title . "\n";
|
|
||||||
|
|
||||||
$article = file_get_contents($item->link, false, $context);
|
|
||||||
$doc = new DOMDocument();
|
|
||||||
$doc->loadHTML($article);
|
|
||||||
|
|
||||||
$finder = new DomXPath($doc);
|
|
||||||
|
|
||||||
// clean images
|
|
||||||
$figures = $finder->query('//figure');
|
|
||||||
foreach ($figures as $figure)
|
|
||||||
{
|
|
||||||
$figure->parentNode->removeChild($figure);
|
|
||||||
}
|
|
||||||
|
|
||||||
// clean "à lire aussi" and inline quotes
|
|
||||||
$asides = $finder->query('//aside');
|
|
||||||
foreach ($asides as $aside)
|
|
||||||
{
|
|
||||||
$aside->parentNode->removeChild($aside);
|
|
||||||
}
|
|
||||||
|
|
||||||
// improve section titles
|
|
||||||
$asides = $finder->query('//h2');
|
|
||||||
foreach ($asides as $aside)
|
|
||||||
{
|
|
||||||
$aside->textContent = "\n*" . $aside->textContent . "*\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output
|
|
||||||
$result .= "\n------\n\n";
|
|
||||||
$result .= "Article : " . $item->title . "\n";
|
|
||||||
$result .= 'Catégorie : ' . str_replace("\n", '', $category) . "\n";
|
|
||||||
$result .= 'Auteur.ice : ' . $author . "\n";
|
|
||||||
$result .= "Introduction : " . $summary . "\n";
|
|
||||||
$result .= "\n";
|
|
||||||
|
|
||||||
// article main text
|
// Add to content
|
||||||
$maintext = $finder->query('//div[contains(@class, "paywall-restricted-content")]');
|
$header .= '- ' . $title . "\n";
|
||||||
$result .= $maintext->item(0)->textContent;
|
|
||||||
|
$article = file_get_contents($item->link, false, $context);
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadHTML($article);
|
||||||
|
|
||||||
|
$finder = new DomXPath($doc);
|
||||||
|
|
||||||
|
// clean images
|
||||||
|
$figures = $finder->query('//figure');
|
||||||
|
foreach ($figures as $figure)
|
||||||
|
{
|
||||||
|
$figure->parentNode->removeChild($figure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clean "à lire aussi" and inline quotes
|
||||||
|
$asides = $finder->query('//aside');
|
||||||
|
foreach ($asides as $aside)
|
||||||
|
{
|
||||||
|
$aside->parentNode->removeChild($aside);
|
||||||
|
}
|
||||||
|
|
||||||
|
// improve section titles
|
||||||
|
$asides = $finder->query('//h2');
|
||||||
|
foreach ($asides as $aside)
|
||||||
|
{
|
||||||
|
$aside->textContent = "\n*" . $aside->textContent . "*\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output
|
||||||
|
$result .= "\n------\n\n";
|
||||||
|
$result .= "Article : " . $item->title . "\n";
|
||||||
|
$result .= "Date : " . $item->pubDate . "\n";
|
||||||
|
$result .= 'Catégorie : ' . str_replace("\n", '', $category) . "\n";
|
||||||
|
$result .= 'Auteur.ice : ' . $author . "\n";
|
||||||
|
$result .= "Introduction : " . $summary . "\n";
|
||||||
|
$result .= "\n";
|
||||||
|
|
||||||
|
// article main text
|
||||||
|
$maintext = $finder->query('//div[contains(@class, "paywall-restricted-content")]');
|
||||||
|
$result .= $maintext->item(0)->textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = 'mediapart' . str_replace(' ', '', $localedate) . '.txt';
|
$filename = 'mediapart' . str_replace(' ', '', $localedate) . '.txt';
|
||||||
|
|
Loading…
Reference in New Issue