diff options
| author | horus | 2020-07-23 19:02:44 +0200 |
|---|---|---|
| committer | horus | 2020-07-23 19:02:44 +0200 |
| commit | c4b821cc89cd80cb23f52c5d38e90f6defb2e835 (patch) | |
| tree | 5e37961812fabaf198016e7c6887eb8a5925741d | |
| parent | 675109d7344a222de5cf8bb843b1f7ec2942b69f (diff) | |
| download | senpai-c4b821cc89cd80cb23f52c5d38e90f6defb2e835.tar.gz | |
Replaced is_airing with airing_status.
| -rw-r--r-- | app/Anime.php | 5 | ||||
| -rw-r--r-- | app/Console/Kernel.php | 11 | ||||
| -rw-r--r-- | app/Http/Controllers/AnimeController.php | 2 | ||||
| -rw-r--r-- | app/Libraries/Background.php | 17 | ||||
| -rw-r--r-- | database/migrations/2020_07_23_185334_add_airing_status_to_view_anime.php | 87 | ||||
| -rw-r--r-- | database/seeds/AiringStatusSeeder.php | 8 |
6 files changed, 112 insertions, 18 deletions
diff --git a/app/Anime.php b/app/Anime.php index 4c72910..6f7f0c1 100644 --- a/app/Anime.php +++ b/app/Anime.php @@ -26,7 +26,8 @@ class Anime extends Model { 'anime_type', 'broadcasted', 'episodes', - 'is_airing' + 'is_airing', + 'airing_status' ]; public function __construct() { @@ -72,6 +73,8 @@ class Anime extends Model { $this->episodes = $animeInfo->getEpisodes(); $this->is_airing = $animeInfo->isAiring(); + + $this->airing_status = getAiringStatusCode($animeInfo->getStatus()); } public function getStats() { diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index f7dc4eb..6f99217 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -69,13 +69,16 @@ class Kernel extends ConsoleKernel })->weeklyOn(1, '15:30'); #})->everyMinute(); -/* + /* $schedule->call( function(){ $background = new Background(); - $anime = Anime::where('mal_id', 40591)->get()->first(); - $background->saveAiring( $anime ); + #$background->checkIfIsAiring(); + $background->saveSeason(); + #$anime = Anime::where('mal_id', 40591)->get()->first(); + #$background->saveAiring( $anime ); })->everyMinute(); -*/ + #})->twiceDaily(9, 23); + */ } /** diff --git a/app/Http/Controllers/AnimeController.php b/app/Http/Controllers/AnimeController.php index 2f46cd5..461b583 100644 --- a/app/Http/Controllers/AnimeController.php +++ b/app/Http/Controllers/AnimeController.php @@ -97,7 +97,7 @@ class AnimeController extends Controller { $most_surprising_anime = $most_surprising_anime->simplePaginate(10); #$anime = $anime->setTable('anime'); - $anime = $anime->where('is_airing', 1); + $anime = $anime->where('airing_status', env('ANIME_IS_AIRING')); $anime = $anime->orderBy('watching', 'desc'); $anime = $anime->orderBy('members', 'desc'); $anime = $anime->orderBy('score_today', 'desc'); diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index db9e42f..2d7c7fb 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -19,7 +19,7 @@ use Eluceo\iCal\Component\Event; class Background { public function saveAiring(Anime $anime) { - if ( ! $anime->is_airing ) { + if ( $anime->airing_status != env("ANIME_IS_AIRING") ) { echo "saveAiring: Anime (" . $anime->mal_id . ") is not airing. Skipping.\n"; return; } @@ -105,7 +105,7 @@ class Background { } public function saveAiringForAll() { - $anime_all = Anime::where('is_airing', true)->get(); + $anime_all = Anime::where('airing_status', env('ANIME_IS_AIRING'))->get(); foreach( $anime_all as $anime ) { $this->saveAiring($anime); sleep(1); @@ -140,7 +140,8 @@ class Background { * Sleep to avoid 403 by MAL. */ sleep(10); - $anime->fill( $entry->getMalID(), $is_airing=true ); + #$anime->fill( $entry->getMalID(), $is_airing=true ); + $anime->fill( $entry->getMalID() ); if ( "" == $anime->url ) { echo "saveSeason: url is empty for: " . $entry->getMalId() . "\n"; @@ -182,7 +183,7 @@ class Background { public function checkIfIsAiring() { $jikan = new Malclient; - foreach( Anime::where('airing_status', '=', 4)->get() as $anime) { + foreach( Anime::where('airing_status', '!=', env('ANIME_FINISHED_AIRING'))->get() as $anime) { try { $animeInfo = $jikan->getAnime( (new \Jikan\Request\Anime\AnimeRequest( $anime->mal_id )) @@ -197,12 +198,12 @@ class Background { $airing_status = getAiringStatusCode( $animeInfo->getStatus() ); - if ( ! $animeInfo->isAiring() ) { + if ( $anime->airing_status != $airing_status ) { DB::table('anime') ->where('mal_id', $anime->mal_id) - ->update(['is_airing' => false, 'airing_status' => $airing_status]); + ->update(['airing_status' => $airing_status]); } - sleep(10); + sleep(5); } } @@ -239,7 +240,7 @@ class Background { } public function saveEnhancementForAll() { - $anime_all = Anime::where('is_airing', true)->where('synopsis', '')->get(); + $anime_all = Anime::where('airing_status', env('ANIME_IS_AIRING'))->where('synopsis', '')->get(); foreach( $anime_all as $anime ) { $this->addEnhancementToAnime($anime); sleep(1); diff --git a/database/migrations/2020_07_23_185334_add_airing_status_to_view_anime.php b/database/migrations/2020_07_23_185334_add_airing_status_to_view_anime.php new file mode 100644 index 0000000..aa99e08 --- /dev/null +++ b/database/migrations/2020_07_23_185334_add_airing_status_to_view_anime.php @@ -0,0 +1,87 @@ +<?php + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +class AddAiringStatusToViewAnime extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + DB::statement( + "CREATE OR REPLACE VIEW view_anime_index AS + SELECT DISTINCT + a.mal_id, + url, + image_url, + title_pref as title, + title_pref, + anime_type, + a.created_at, + a.updated_at, + episodes, + is_airing, + synopsis, + hashtag, + airing_status, + (SELECT score FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at ASC LIMIT 1) as score_begin, + (SELECT score FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as score_today, + (SELECT watching FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as watching, + (SELECT members FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as members + FROM + anime as a + JOIN + stats as s ON a.mal_id = s.mal_id + WHERE + score IS NOT null + ORDER BY + abs(score_today-score_begin) DESC, + is_airing DESC + ;" + ); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + DB::statement( + "ALTER VIEW view_anime_index AS + SELECT DISTINCT + a.mal_id, + url, + image_url, + title_pref as title, + title_pref, + anime_type, + a.created_at, + a.updated_at, + episodes, + is_airing, + synopsis, + hashtag, + (SELECT score FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at ASC LIMIT 1) as score_begin, + (SELECT score FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as score_today, + (SELECT watching FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as watching, + (SELECT members FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as members + FROM + anime as a + JOIN + stats as s ON a.mal_id = s.mal_id + WHERE + score IS NOT null + ORDER BY + abs(score_today-score_begin) DESC, + is_airing DESC + ;" + ); + } +} diff --git a/database/seeds/AiringStatusSeeder.php b/database/seeds/AiringStatusSeeder.php index 7017842..e968886 100644 --- a/database/seeds/AiringStatusSeeder.php +++ b/database/seeds/AiringStatusSeeder.php @@ -12,19 +12,19 @@ class AiringStatusSeeder extends Seeder public function run() { DB::table('airing_status')->insert([ - 'id' => 1, + 'id' => env('ANIME_IS_AIRING'), 'status' => 'Currently Airing' ]); DB::table('airing_status')->insert([ - 'id' => 2, + 'id' => env('ANIME_FINISHED_AIRING'), 'status' => 'Finished Airing' ]); DB::table('airing_status')->insert([ - 'id' => 3, + 'id' => env('ANIME_NOT_YET_AIRED'), 'status' => 'Not Yet Aired' ]); DB::table('airing_status')->insert([ - 'id' => 4, + 'id' => env('ANIME_AIRED_UNKNOWN'), 'status' => 'Unknown' ]); } |
