mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
update & separate genre indexer: indexer:genres
This commit is contained in:
parent
97b3a10253
commit
01e29b06d5
@ -113,22 +113,49 @@ class CommonIndexer extends Command
|
|||||||
'json'
|
'json'
|
||||||
),
|
),
|
||||||
true
|
true
|
||||||
)['genres'];
|
);
|
||||||
|
|
||||||
if (HttpHelper::hasError($results)) {
|
if (HttpHelper::hasError($results)) {
|
||||||
echo "FAILED: {$results->original['error']}\n";
|
echo "FAILED: {$results->original['error']}\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemCount = count($results);
|
$itemCount = count($results['genres']);
|
||||||
echo "Parsed {$itemCount} anime genres\n";
|
echo "Parsed {$itemCount} anime genres\n";
|
||||||
foreach ($results as $i => $item) {
|
foreach ($results['genres'] as $i => $item) {
|
||||||
$result = DB::table('genres_anime')
|
$result = DB::table('genres_anime')
|
||||||
->where('mal_id', $item['mal_id'])
|
->where('mal_id', $item['mal_id'])
|
||||||
->updateOrInsert(['request_hash'=>'request:anime_genres:'.sha1($item['mal_id'].$item['name'])]+$item);
|
->updateOrInsert(['request_hash'=>'request:anime_genres:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
echo "Indexing {$i}/{$itemCount} \r";
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['explicit_genres']);
|
||||||
|
echo "Parsed {$itemCount} anime explicit_genres\n";
|
||||||
|
foreach ($results['explicit_genres'] as $i => $item) {
|
||||||
|
$result = DB::table('explicit_genres_anime')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:anime_explicit_genres:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['themes']);
|
||||||
|
echo "Parsed {$itemCount} anime themes\n";
|
||||||
|
foreach ($results['themes'] as $i => $item) {
|
||||||
|
$result = DB::table('themes_anime')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:anime_themes:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['demographics']);
|
||||||
|
echo "Parsed {$itemCount} anime demographics\n";
|
||||||
|
foreach ($results['demographics'] as $i => $item) {
|
||||||
|
$result = DB::table('demographics_anime')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:anime_demographics:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manga Genres
|
* Manga Genres
|
||||||
*/
|
*/
|
||||||
|
158
app/Console/Commands/Indexer/GenreIndexer.php
Normal file
158
app/Console/Commands/Indexer/GenreIndexer.php
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Indexer;
|
||||||
|
|
||||||
|
use App\Http\HttpHelper;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Jikan\Request\Genre\AnimeGenresRequest;
|
||||||
|
use Jikan\Request\Genre\MangaGenresRequest;
|
||||||
|
|
||||||
|
class GenreIndexer extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*`
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'indexer:genres';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Index Anime & Manga Genres';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
echo "Note: If an entry already exists, it will be updated instead.\n\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anime Genres
|
||||||
|
*/
|
||||||
|
echo "Indexing Anime Genres...\n";
|
||||||
|
$results = \json_decode(
|
||||||
|
app('SerializerV4')->serialize(
|
||||||
|
app('JikanParser')
|
||||||
|
->getAnimeGenres(new AnimeGenresRequest()),
|
||||||
|
'json'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
if (HttpHelper::hasError($results)) {
|
||||||
|
echo "FAILED: {$results->original['error']}\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['genres']);
|
||||||
|
echo "Parsed {$itemCount} anime genres\n";
|
||||||
|
foreach ($results['genres'] 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);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['explicit_genres']);
|
||||||
|
echo "Parsed {$itemCount} anime explicit_genres\n";
|
||||||
|
foreach ($results['explicit_genres'] as $i => $item) {
|
||||||
|
$result = DB::table('explicit_genres_anime')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:anime_explicit_genres:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['themes']);
|
||||||
|
echo "Parsed {$itemCount} anime themes\n";
|
||||||
|
foreach ($results['themes'] as $i => $item) {
|
||||||
|
$result = DB::table('themes_anime')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:anime_themes:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['demographics']);
|
||||||
|
echo "Parsed {$itemCount} anime demographics\n";
|
||||||
|
foreach ($results['demographics'] as $i => $item) {
|
||||||
|
$result = DB::table('demographics_anime')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:anime_demographics:'.sha1($item['mal_id'].$item['name'])]+$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
|
||||||
|
);
|
||||||
|
|
||||||
|
if (HttpHelper::hasError($results)) {
|
||||||
|
echo "FAILED: {$results->original['error']}\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['genres']);
|
||||||
|
echo "Parsed {$itemCount} manga genres\n";
|
||||||
|
foreach ($results['genres'] as $i => $item) {
|
||||||
|
$result = DB::table('genres_manga')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:manga_genres:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['explicit_genres']);
|
||||||
|
echo "Parsed {$itemCount} manga explicit_genres\n";
|
||||||
|
foreach ($results['explicit_genres'] as $i => $item) {
|
||||||
|
$result = DB::table('explicit_genres_manga')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:manga_explicit_genres:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['themes']);
|
||||||
|
echo "Parsed {$itemCount} manga themes\n";
|
||||||
|
foreach ($results['themes'] as $i => $item) {
|
||||||
|
$result = DB::table('themes_manga')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:manga_themes:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCount = count($results['demographics']);
|
||||||
|
echo "Parsed {$itemCount} manga demographics\n";
|
||||||
|
foreach ($results['demographics'] as $i => $item) {
|
||||||
|
$result = DB::table('demographics_manga')
|
||||||
|
->where('mal_id', $item['mal_id'])
|
||||||
|
->updateOrInsert(['request_hash'=>'request:manga_demographics:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||||
|
echo "Indexing {$i}/{$itemCount} \r";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo str_pad("Indexing complete", 10).PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
@ -12,8 +12,8 @@ use App\Console\Commands\Indexer\AnimeIndexer;
|
|||||||
use App\Console\Commands\Indexer\AnimeScheduleIndexer;
|
use App\Console\Commands\Indexer\AnimeScheduleIndexer;
|
||||||
use App\Console\Commands\Indexer\CommonIndexer;
|
use App\Console\Commands\Indexer\CommonIndexer;
|
||||||
use App\Console\Commands\Indexer\CurrentSeasonIndexer;
|
use App\Console\Commands\Indexer\CurrentSeasonIndexer;
|
||||||
|
use App\Console\Commands\Indexer\GenreIndexer;
|
||||||
use App\Console\Commands\Indexer\MangaIndexer;
|
use App\Console\Commands\Indexer\MangaIndexer;
|
||||||
use App\Console\Commands\Indexer\ScheduleIndexer;
|
|
||||||
use App\Console\Commands\ManageMicrocaching;
|
use App\Console\Commands\ManageMicrocaching;
|
||||||
use App\Console\Commands\ModifyCacheDriver;
|
use App\Console\Commands\ModifyCacheDriver;
|
||||||
use App\Console\Commands\ModifyCacheMethod;
|
use App\Console\Commands\ModifyCacheMethod;
|
||||||
@ -38,7 +38,8 @@ class Kernel extends ConsoleKernel
|
|||||||
CurrentSeasonIndexer::class,
|
CurrentSeasonIndexer::class,
|
||||||
ManageMicrocaching::class,
|
ManageMicrocaching::class,
|
||||||
AnimeIndexer::class,
|
AnimeIndexer::class,
|
||||||
MangaIndexer::class
|
MangaIndexer::class,
|
||||||
|
GenreIndexer::class
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,5 +62,8 @@ class Kernel extends ConsoleKernel
|
|||||||
// Update common indexes daily
|
// Update common indexes daily
|
||||||
$schedule->command('indexer:common')
|
$schedule->command('indexer:common')
|
||||||
->daily();
|
->daily();
|
||||||
|
|
||||||
|
$schedule->command('indexer:genres')
|
||||||
|
->daily();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
composer.lock
generated
8
composer.lock
generated
@ -2931,12 +2931,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/jikan-me/jikan.git",
|
"url": "https://github.com/jikan-me/jikan.git",
|
||||||
"reference": "77a6ea88472aad8ab3f6a7ae485341fb4c7c6c6e"
|
"reference": "74209b3b675bdbfc09fc5e6d53cbafdc89a04cf4"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/jikan-me/jikan/zipball/77a6ea88472aad8ab3f6a7ae485341fb4c7c6c6e",
|
"url": "https://api.github.com/repos/jikan-me/jikan/zipball/74209b3b675bdbfc09fc5e6d53cbafdc89a04cf4",
|
||||||
"reference": "77a6ea88472aad8ab3f6a7ae485341fb4c7c6c6e",
|
"reference": "74209b3b675bdbfc09fc5e6d53cbafdc89a04cf4",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -2985,7 +2985,7 @@
|
|||||||
"type": "patreon"
|
"type": "patreon"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2021-11-12T22:51:32+00:00"
|
"time": "2021-11-12T23:18:34+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "jms/metadata",
|
"name": "jms/metadata",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user