summaryrefslogtreecommitdiff
path: root/app/Anime.php
diff options
context:
space:
mode:
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;
}