51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Post;
|
|
use Illuminate\Console\Attributes\Description;
|
|
use Illuminate\Console\Attributes\Signature;
|
|
|
|
#[Signature('direct:scrape-feed')]
|
|
#[Description('Scrape the Instagram following feed via Playwright')]
|
|
class ScrapeFeed extends RunsPlaywrightScript
|
|
{
|
|
protected string $script = 'scrape-feed.spec.js';
|
|
|
|
protected function afterRun(): void
|
|
{
|
|
$path = base_path('playwright/output/scrape-feed.json');
|
|
|
|
if (! file_exists($path)) {
|
|
$this->warn('No output file found — nothing to upsert.');
|
|
return;
|
|
}
|
|
|
|
$posts = json_decode(file_get_contents($path), true);
|
|
|
|
foreach ($posts as $post) {
|
|
Post::updateOrCreate(
|
|
['id' => $post['id']],
|
|
[
|
|
'code' => $post['code'],
|
|
'username' => $post['username'],
|
|
'full_name' => $post['full_name'],
|
|
'caption' => $post['caption'],
|
|
'accessibility_caption' => $post['accessibility_caption'],
|
|
'is_video' => $post['is_video'],
|
|
'is_carousel' => $post['is_carousel'],
|
|
'like_count' => $post['like_count'],
|
|
'comment_count' => $post['comment_count'],
|
|
'taken_at' => $post['taken_at'],
|
|
'image_url' => $post['image_url'],
|
|
'video_url' => $post['video_url'],
|
|
'carousel_images' => $post['carousel_images'],
|
|
'profile_pic_url' => $post['profile_pic_url'],
|
|
]
|
|
);
|
|
}
|
|
|
|
$this->info('Upserted ' . count($posts) . ' posts.');
|
|
}
|
|
}
|