summaryrefslogtreecommitdiff
path: root/app/Anime.php
diff options
context:
space:
mode:
authorhorus2022-11-17 18:51:54 +0100
committerhorus2022-11-17 18:51:54 +0100
commitf2e76ff110f531703f2c4f400e1fa285ee05ad94 (patch)
tree40dcdd85bf3b798b4841b4c05f29b85cdde662fc /app/Anime.php
parente730f497203423c4b9443cd8dbb06eec6274d75a (diff)
downloadsenpai-f2e76ff110f531703f2c4f400e1fa285ee05ad94.tar.gz
Fix for 9.x upgrade + better handling of Anistats rate limiting
Diffstat (limited to 'app/Anime.php')
-rw-r--r--app/Anime.php19
1 files changed, 16 insertions, 3 deletions
diff --git a/app/Anime.php b/app/Anime.php
index 4999c1b..ab5a3fe 100644
--- a/app/Anime.php
+++ b/app/Anime.php
@@ -5,6 +5,7 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\Log;
use Jikan\MyAnimeList\MalClient;
@@ -34,7 +35,7 @@ class Anime extends Model {
public function __construct() {
}
- public function fill( $id, $skip_if_unpopular = true ) {
+ public function fillStats( $id, $skip_if_unpopular = true ) {
$this->mal_id = $id;
$jikan = new Malclient;
@@ -143,7 +144,7 @@ class Anime extends Model {
$data = json_decode( $response->getBody() )->data->Media;
} catch (\Exception $e) {
- echo "Problem with Guzzle connecting to Anilist on anime: (" . $this->mal_id . ")\n";
+ echo "getDataFromAnilist: Problem with Guzzle connecting to Anilist on anime: (" . $this->mal_id . ")\n";
return "";
}
return $data;
@@ -178,10 +179,22 @@ class Anime extends Model {
]);
$data = json_decode( $response->getBody() )->data->Media;
+
+ $rate_limit = $response->getHeader("X-RateLimit-Remaining")[0];
+ echo "Try Block: Rate Limit: " . $rate_limit . "\n";
+ Log::info("getEnhancementFromAnilist: Try Block: Rate Limit: " . $rate_limit . "\n");
+ if ( $rate_limit <= 10 ) {
+ echo " sleep 5 seconds\n\n";
+ sleep(5);
+ }
} catch (\Exception $e) {
- echo "Problem with Guzzle connecting to Anilist on anime: (" . $this->mal_id . ")\n";
+ echo "getEnhancementFromAnilist: Problem with Guzzle connecting to Anilist on anime: (" . $this->mal_id . ")\n";
+ echo $e->getMessage();
+ echo "\n";
return "";
}
+ echo "got enhancement for anime " . $this->mal_id . "\n\n";
+ Log::info("got enhancement for anime " . $this->mal_id . "\n");
return $data;
}