summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus2020-09-23 14:33:19 +0200
committerhorus2020-09-23 14:33:19 +0200
commitdc3df89aa73d9df48f92b22378a1307b4ddba3c7 (patch)
treeeeadf2376d69a7c8479db76fcab4a95600dd6716
parent82b2360c4f6186feaa43023dcd79fb89d91c9d4d (diff)
downloadsenpai-dc3df89aa73d9df48f92b22378a1307b4ddba3c7.tar.gz
only save stats if no error
-rw-r--r--app/AnimeStats.php17
-rw-r--r--app/Libraries/Background.php7
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);