From 675109d7344a222de5cf8bb843b1f7ec2942b69f Mon Sep 17 00:00:00 2001 From: horus Date: Thu, 23 Jul 2020 17:15:11 +0200 Subject: Bugfix. Correctly detects airing anime. --- app/Libraries/Background.php | 8 ++++++-- app/helpers.php | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index 920c866..db9e42f 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -182,7 +182,7 @@ class Background { public function checkIfIsAiring() { $jikan = new Malclient; - foreach( Anime::where('is_airing', true)->get() as $anime) { + foreach( Anime::where('airing_status', '=', 4)->get() as $anime) { try { $animeInfo = $jikan->getAnime( (new \Jikan\Request\Anime\AnimeRequest( $anime->mal_id )) @@ -191,14 +191,18 @@ class Background { echo "checkIfIsAiring: Problem requesting AnimeInfo for (" . $anime->mal_id . ") continue\n"; echo $e->getMessage(); echo "\n\n"; + sleep(10); continue; } + + $airing_status = getAiringStatusCode( $animeInfo->getStatus() ); if ( ! $animeInfo->isAiring() ) { DB::table('anime') ->where('mal_id', $anime->mal_id) - ->update(['is_airing' => false]); + ->update(['is_airing' => false, 'airing_status' => $airing_status]); } + sleep(10); } } diff --git a/app/helpers.php b/app/helpers.php index 0953a56..7ac1fd6 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -58,3 +58,11 @@ function printScoreData($score_array) { return $return; } + +function getAiringStatusCode($airing_status) { + $status = DB::select("SELECT id FROM airing_status WHERE status = ?", array($airing_status)); + if ( empty($status) ) { + return 4; + } + return $status[0]->id; +} -- cgit v1.2.3