From dc3df89aa73d9df48f92b22378a1307b4ddba3c7 Mon Sep 17 00:00:00 2001 From: horus Date: Wed, 23 Sep 2020 14:33:19 +0200 Subject: only save stats if no error --- app/AnimeStats.php | 17 +++++++++++++---- app/Libraries/Background.php | 7 ++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/AnimeStats.php b/app/AnimeStats.php index a4f3396..9b9b850 100644 --- a/app/AnimeStats.php +++ b/app/AnimeStats.php @@ -94,9 +94,16 @@ class AnimeStats extends Model { $this->season_name= $season_name; } - $animeInfo = $jikan->getAnime( - (new \Jikan\Request\Anime\AnimeRequest( $this->mal_id )) - ); + try { + $animeInfo = $jikan->getAnime( + (new \Jikan\Request\Anime\AnimeRequest( $this->mal_id )) + ); + } catch (\Exception $e) { + echo "Error requesting AnimeInfo for " . $this->mal_id ."\n"; + echo "Message: " . $e->getMessage(); + echo "\n\n"; + return false; + } $this->score = $animeInfo->getScore(); $this->scored_by = $animeInfo->getScoredBy(); $this->rank = $animeInfo->getRank(); @@ -112,7 +119,7 @@ class AnimeStats extends Model { echo "Error requesting AnimeStats for " . $this->mal_id ."\n"; echo "Message: " . $e->getMessage(); echo "\n\n"; - return; + return false; } $this->watching = $animeStats->getWatching(); @@ -173,6 +180,8 @@ class AnimeStats extends Model { } else { $this->score_10 = 0; } + + return true; } public function anime() { diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index 2d63a3e..5334480 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -149,9 +149,10 @@ class Background { echo "Getting stats for " . $entry->mal_id ."\n"; $animeStats = new AnimeStats(); - $animeStats->fill( $entry->mal_id ); - - $animeStats->save(); + if ( $animeStats->fill($entry->mal_id) ) { + # Only save if no error + $animeStats->save(); + } # sleep to avoid 403 sleep(5); -- cgit v1.2.3