Add Minoos support

This commit is contained in:
Mohamed jinas
2024-01-12 04:34:28 +05:00
parent fbaa43748f
commit 46e2e849bb
5 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Services\MinoosService;
use App\Topic;
use App\Source;
class ScrapeMinoosCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'scrape:minoos';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scrape Minoos';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$source = Source::where('slug', 'minoos')->first();
$articles = (new MinoosService)->scrape();
foreach ($articles as $article) {
// Attach the relationship between source and article and return the curren article instance
$articleModel = $source->articles()->updateOrCreate(["guid" => $article["guid"]],
[
"title" => $article["title"],
"url" => $article["url"],
"author" => $article["author"],
"featured_image" => $article["image"],
"body" => $article["content"],
"published_date" => $article["date"],
"meta" => [
"title" => $article["title"],
"highlights" => $article["highlights"]
]
]);
collect($article["topics"])->each(function($topic) use ($articleModel) {
$topicModel = Topic::firstOrCreate(["slug" => $topic["slug"]],["name" => $topic["name"]]);
$topicModel->articles()->syncWithoutDetaching($articleModel);
});
}
}
}

View File

@@ -105,6 +105,10 @@ class Kernel extends ConsoleKernel
$schedule->command('scrape:adhadhu')->everyFiveMinutes()
->runInBackground()
->pingOnSuccess(config('app.url') . "/api/ping/adhadhu");
$schedule->command('scrape:minoos')->everyFiveMinutes()
->runInBackground()
->pingOnSuccess(config('app.url') . "/api/ping/minoos");
}