64 lines
1.3 KiB
PHP
64 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Source;
|
|
use Illuminate\Console\Command;
|
|
use App\Services\MihaaruService;
|
|
|
|
class ScrapeMihaaruCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'scrape:mihaaru';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Scrape Mihaaru mv';
|
|
|
|
/**
|
|
* 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', 'mihaaru')->first();
|
|
|
|
$articles = (new MihaaruService)->scrape();
|
|
|
|
foreach($articles as $article)
|
|
{
|
|
$source->articles()->firstOrCreate([
|
|
"title" => $article["title"],
|
|
"url" => $article["url"],
|
|
"author" => $article["author"],
|
|
"featured_image" => $article["image"],
|
|
"body" => $article["content"],
|
|
"guid" => $article["guid"],
|
|
"published_date" => $article["date"],
|
|
|
|
]);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|