mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
add initial indexing command for producers, maagazines, genres
This commit is contained in:
parent
155aeb0a0f
commit
249a090451
159
app/Console/Commands/CommonIndexing.php
Normal file
159
app/Console/Commands/CommonIndexing.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\HttpHelper;
|
||||
use App\Http\HttpResponse;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Jikan\Request\Genre\AnimeGenresRequest;
|
||||
use Jikan\Request\Genre\MangaGenresRequest;
|
||||
use Jikan\Request\Magazine\MagazinesRequest;
|
||||
use Jikan\Request\Producer\ProducersRequest;
|
||||
|
||||
class CommonIndexing extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'indexing:start';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Index common endpoints';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
echo "Note: Indexer will update entries if they already exist.\n\n";
|
||||
|
||||
/**
|
||||
* Producers
|
||||
*/
|
||||
echo "Indexing Producers...\n";
|
||||
$results = \json_decode(
|
||||
app('SerializerV4')->serialize(
|
||||
app('JikanParser')
|
||||
->getProducers(new ProducersRequest()),
|
||||
'json'
|
||||
),
|
||||
true
|
||||
)['producers'];
|
||||
|
||||
if (HttpHelper::hasError($results)) {
|
||||
echo "FAILED: {$results->original['error']}\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCount = count($results);
|
||||
echo "Parsed {$itemCount} producers\n";
|
||||
foreach ($results as $i => $item) {
|
||||
$result = DB::table('producers')
|
||||
->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(['request_hash'=>'request:magazines:'.sha1($item['mal_id'].$item['name'].$item['count'])]+$item);
|
||||
echo "Indexing {$i}/{$itemCount} \r";
|
||||
}
|
||||
|
||||
/**
|
||||
* Magazines
|
||||
*/
|
||||
echo "Indexing Magazines...\n";
|
||||
$results = \json_decode(
|
||||
app('SerializerV4')->serialize(
|
||||
app('JikanParser')
|
||||
->getMagazines(new MagazinesRequest()),
|
||||
'json'
|
||||
),
|
||||
true
|
||||
)['magazines'];
|
||||
|
||||
if (HttpHelper::hasError($results)) {
|
||||
echo "FAILED: {$results->original['error']}\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCount = count($results);
|
||||
echo "Parsed {$itemCount} magazines\n";
|
||||
foreach ($results as $i => $item) {
|
||||
$result = DB::table('magazines')
|
||||
->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(['request_hash'=>'request:magazines:'.sha1($item['mal_id'].$item['name'].$item['count'])]+$item);
|
||||
echo "Indexing {$i}/{$itemCount} \r";
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime Genres
|
||||
*/
|
||||
echo "Indexing Anime Genres...\n";
|
||||
$results = \json_decode(
|
||||
app('SerializerV4')->serialize(
|
||||
app('JikanParser')
|
||||
->getAnimeGenres(new AnimeGenresRequest()),
|
||||
'json'
|
||||
),
|
||||
true
|
||||
)['genres'];
|
||||
|
||||
if (HttpHelper::hasError($results)) {
|
||||
echo "FAILED: {$results->original['error']}\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCount = count($results);
|
||||
echo "Parsed {$itemCount} anime genres\n";
|
||||
foreach ($results as $i => $item) {
|
||||
$result = DB::table('genres_anime')
|
||||
->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(['request_hash'=>'request:anime_genres:'.sha1($item['mal_id'].$item['name'].$item['count'])]+$item);
|
||||
echo "Indexing {$i}/{$itemCount} \r";
|
||||
}
|
||||
|
||||
/**
|
||||
* Manga Genres
|
||||
*/
|
||||
echo "Indexing Manga Genres...\n";
|
||||
$results = \json_decode(
|
||||
app('SerializerV4')->serialize(
|
||||
app('JikanParser')
|
||||
->getMangaGenres(new MangaGenresRequest()),
|
||||
'json'
|
||||
),
|
||||
true
|
||||
)['genres'];
|
||||
|
||||
if (HttpHelper::hasError($results)) {
|
||||
echo "FAILED: {$results->original['error']}\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCount = count($results);
|
||||
echo "Parsed {$itemCount} manga genres\n";
|
||||
foreach ($results as $i => $item) {
|
||||
$result = DB::table('genres_manga')
|
||||
->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(['request_hash'=>'request:anime_manga:'.sha1($item['mal_id'].$item['name'].$item['count'])]+$item);
|
||||
echo "Indexing {$i}/{$itemCount} \r";
|
||||
}
|
||||
echo str_pad("Indexing complete", 10).PHP_EOL;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ use App\Console\Commands\BlacklistFlush;
|
||||
use App\Console\Commands\BlacklistRemove;
|
||||
use App\Console\Commands\ClearQueuedJobs;
|
||||
use App\Console\Commands\CacheRemove;
|
||||
use App\Console\Commands\CommonIndexing;
|
||||
use App\Console\Commands\ModifyCacheDriver;
|
||||
use App\Console\Commands\ModifyCacheMethod;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
@ -27,7 +28,8 @@ class Kernel extends ConsoleKernel
|
||||
CacheRemove::class,
|
||||
BlacklistAdd::class,
|
||||
BlacklistRemove::class,
|
||||
BlacklistFlush::class
|
||||
BlacklistFlush::class,
|
||||
CommonIndexing::class
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@
|
||||
"flipbox/lumen-generator": "^6",
|
||||
"illuminate/redis": "^7",
|
||||
"jenssegers/mongodb": "^4.0",
|
||||
"jikan-me/jikan": "v3.0.0-alpha.15",
|
||||
"jikan-me/jikan": "v3.0.0-alpha.16",
|
||||
"jms/serializer": "^1.13",
|
||||
"laravel/lumen-framework": "^7.0",
|
||||
"league/flysystem": "^1.0",
|
||||
|
12
composer.lock
generated
12
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "2d853b1c159b5aa408af30b54c37c51f",
|
||||
"content-hash": "2aa457b1ebc4916d31595557c9a0d095",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@ -2210,16 +2210,16 @@
|
||||
},
|
||||
{
|
||||
"name": "jikan-me/jikan",
|
||||
"version": "v3.0.0-alpha.15",
|
||||
"version": "v3.0.0-alpha.16",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jikan-me/jikan.git",
|
||||
"reference": "d285b878e316d72f0b9f7d22c648da22c00860da"
|
||||
"reference": "9e66270bac020ed5eb919d7f4b7a9d70752d6655"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/jikan-me/jikan/zipball/d285b878e316d72f0b9f7d22c648da22c00860da",
|
||||
"reference": "d285b878e316d72f0b9f7d22c648da22c00860da",
|
||||
"url": "https://api.github.com/repos/jikan-me/jikan/zipball/9e66270bac020ed5eb919d7f4b7a9d70752d6655",
|
||||
"reference": "9e66270bac020ed5eb919d7f4b7a9d70752d6655",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2257,7 +2257,7 @@
|
||||
}
|
||||
],
|
||||
"description": "Jikan is an unofficial MyAnimeList API",
|
||||
"time": "2020-07-12T14:54:21+00:00"
|
||||
"time": "2020-07-13T13:51:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jms/metadata",
|
||||
|
Loading…
x
Reference in New Issue
Block a user