diff options
Diffstat (limited to 'app/Libraries')
| -rw-r--r-- | app/Libraries/Background.php | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index c491d44..920c866 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -123,6 +123,8 @@ class Background { )) ); + sleep(10); + foreach($season->anime as $entry) { if ( Anime::where('mal_id', $entry->getMalID())->exists() ) { /** @@ -148,6 +150,7 @@ class Background { if( ! DB::table('anime')->where('mal_id', $entry->getMalID() )->exists() ) { $anime->save(); } + sleep(10); } } @@ -157,10 +160,22 @@ class Background { } foreach($anime as $entry ) { + # skip if we have crawled stats from today + if ( ! empty($entry->getStats()->get()->last()) ) { + $date = $entry->getStats()->get()->last()->created_at->toDateTimeString(); + if (date('Ymd') == date('Ymd', strtotime($date)) ) { + continue; + } + } + + echo "Getting stats for " . $entry->mal_id ."\n"; $animeStats = new AnimeStats(); $animeStats->fill( $entry->mal_id ); $animeStats->save(); + + # sleep to avoid 403 + sleep(5); } } @@ -176,6 +191,7 @@ class Background { echo "checkIfIsAiring: Problem requesting AnimeInfo for (" . $anime->mal_id . ") continue\n"; echo $e->getMessage(); echo "\n\n"; + continue; } if ( ! $animeInfo->isAiring() ) { |
