WIP
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Feeds;
|
||||
|
||||
use Goutte\Client;
|
||||
@@ -12,29 +11,38 @@ class RaajjeMvFeed implements Feed
|
||||
{
|
||||
$this->client = new Client();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the latest news
|
||||
* Get all the latest news from the 'އެންމެ ފަސް' section
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
|
||||
$crawler = $this->client->request('GET', "https://raajje.mv/");
|
||||
|
||||
$feeds = [];
|
||||
$articles = $crawler->filter('div[v-if*="homepage.emme_fas"] article-grid')->first()->attr(':collection');
|
||||
// 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());
|
||||
|
||||
$raw_response = json_decode(html_entity_decode($articles), true);
|
||||
foreach($raw_response as $response)
|
||||
{
|
||||
$feeds[] = [
|
||||
"title" => $response["heading"],
|
||||
"link" => "https://raajje.mv/".$response["id"],
|
||||
"date" => $response["approved_date"]
|
||||
];
|
||||
}
|
||||
return [
|
||||
"title" => $title,
|
||||
"link" => "https://raajje.mv" . $link,
|
||||
"date" => $date
|
||||
];
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return $feeds;
|
||||
// Remove null values and flatten the array
|
||||
$articlesContainer = array_filter($articlesContainer);
|
||||
|
||||
return !empty($articlesContainer) ? array_merge(...$articlesContainer) : [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user