Add (ai gen)
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Jobs\ShopeeSellerTopProductScraperJob;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
@@ -10,9 +12,31 @@ class Kernel extends ConsoleKernel
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->command('sitemap:generate')->hourly()->runInBackground();
|
||||
// Schdule MY TECH Category
|
||||
$category = Category::where('country_locale_slug','my')->where('name','Technology')->first();
|
||||
|
||||
if (!is_null($category))
|
||||
{
|
||||
$hour = rand(0, 23);
|
||||
$minute = rand(0, 59);
|
||||
|
||||
$schedule->call(function () use ($category) {
|
||||
|
||||
$shopee_seller_category = \App\Models\ShopeeSellerCategory::where('category_id', $category->id)->where(function($query) {
|
||||
$query->whereNull('last_ai_written_at')
|
||||
->orWhere('last_ai_written_at', '=', \App\Models\ShopeeSellerCategory::whereNotNull('last_ai_written_at')->orderBy('last_ai_written_at', 'asc')->value('last_ai_written_at'));
|
||||
})->first();
|
||||
|
||||
$task = ShopeeSellerTopProductScraperJob::dispatch($shopee_seller_category->seller, $category->country_locale->country_iso, $category)
|
||||
->onQueue('default')
|
||||
->onConnection('default');
|
||||
|
||||
|
||||
})->dailyAt("{$hour}:{$minute}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,4 +48,6 @@ protected function commands(): void
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
use App\Models\AiWriteup;
|
||||
use App\Models\Post;
|
||||
use App\Models\PostCategory;
|
||||
use App\Models\ShopeeSellerCategory;
|
||||
use App\Models\ShopeeSellerScrape;
|
||||
use App\Models\ShopeeSellerScrapedImage;
|
||||
use Exception;
|
||||
@@ -96,6 +97,25 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
$post = Post::create($post_data);
|
||||
|
||||
if (! is_null($post)) {
|
||||
|
||||
$shopee_seller_scrape->write_counts = $shopee_seller_scrape->write_counts + 1;
|
||||
$shopee_seller_scrape->last_ai_written_at = now();
|
||||
$shopee_seller_scrape->save();
|
||||
|
||||
$shopee_seller_category = ShopeeSellerCategory::where('seller', $shopee_seller_scrape->seller)->first();
|
||||
|
||||
if (is_null($shopee_seller_category))
|
||||
{
|
||||
$shopee_seller_category = new ShopeeSellerCategory;
|
||||
$shopee_seller_category->seller = $shopee_seller_scrape->seller;
|
||||
$shopee_seller_category->category_id = $shopee_seller_scrape->category_id;
|
||||
}
|
||||
|
||||
$shopee_seller_category->last_ai_written_at = $shopee_seller_scrape->last_ai_written_at;
|
||||
$shopee_seller_category->write_counts = $shopee_seller_scrape->write_counts;
|
||||
|
||||
$shopee_seller_category->save();
|
||||
|
||||
PostCategory::create([
|
||||
'post_id' => $post->id,
|
||||
'category_id' => $shopee_seller_scrape->category->id,
|
||||
|
||||
@@ -77,7 +77,6 @@ public static function handle(string $seller, string $country_iso, Category $cat
|
||||
$shopee_seller_scrape->epoch = $epoch;
|
||||
$shopee_seller_scrape->filename = $filename;
|
||||
$shopee_seller_scrape->category_id = $category->id;
|
||||
$shopee_seller_scrape->last_ai_written_at = now();
|
||||
|
||||
if ($shopee_seller_scrape->save()) {
|
||||
return (object) compact('seller_shop_task', 'product_task', 'shopee_seller_scrape');
|
||||
|
||||
48
app/Models/ShopeeSellerCategory.php
Normal file
48
app/Models/ShopeeSellerCategory.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class ShopeeSellerCategory
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $seller
|
||||
* @property int $category_id
|
||||
* @property Carbon|null $last_ai_written_at
|
||||
* @property int $write_counts
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property Category $category
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class ShopeeSellerCategory extends Model
|
||||
{
|
||||
protected $table = 'shopee_seller_categories';
|
||||
|
||||
protected $casts = [
|
||||
'category_id' => 'int',
|
||||
'last_ai_written_at' => 'datetime',
|
||||
'write_counts' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'seller',
|
||||
'category_id',
|
||||
'last_ai_written_at',
|
||||
'write_counts'
|
||||
];
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ class ShopeeSellerScrape extends Model
|
||||
'category_id' => 'int',
|
||||
'epoch' => 'int',
|
||||
'last_ai_written_at' => 'datetime',
|
||||
'write_counts' => 'int',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
@@ -41,6 +42,7 @@ class ShopeeSellerScrape extends Model
|
||||
'epoch',
|
||||
'filename',
|
||||
'last_ai_written_at',
|
||||
'write_counts'
|
||||
];
|
||||
|
||||
public function category()
|
||||
|
||||
Reference in New Issue
Block a user