Files
karudhaas/app/Services/Feeds/RaajjeMvFeed.php
Mohamed jinas c8d8ccaebb WIP
2024-01-06 23:48:58 +05:00

49 lines
1.4 KiB
PHP

<?php
namespace App\Services\Feeds;
use Goutte\Client;
class RaajjeMvFeed implements Feed
{
protected $client;
public function __construct()
{
$this->client = new Client();
}
/**
* Get all the latest news from the 'އެންމެ ފަސް' section
*
* @return array
*/
public function get(): array
{
$crawler = $this->client->request('GET', "https://raajje.mv/");
$feeds = [];
// Find the 'އެންމެ ފަސް' section
$articlesContainer = $crawler->filter('.waheed')->each(function ($node) {
// Ensure we are in the right section
if (strpos($node->text(), 'އެންމެ ފަސް') !== false) {
return $node->filter('a')->each(function ($articleNode) {
$link = $articleNode->attr('href');
$title = trim($articleNode->filter('div.leading-relaxed')->text());
$date = trim($articleNode->filter('div.mt-3.text-sm')->text());
return [
"title" => $title,
"link" => "https://raajje.mv" . $link,
"date" => $date
];
});
}
});
// Remove null values and flatten the array
$articlesContainer = array_filter($articlesContainer);
return !empty($articlesContainer) ? array_merge(...$articlesContainer) : [];
}
}