diff options
Diffstat (limited to 'app/Libraries/Background.php')
| -rw-r--r-- | app/Libraries/Background.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index 2985f79..2bfe8a5 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -149,12 +149,20 @@ class Background { $stats_counter = 0; $animeStats = new AnimeStats(); + $failure = 0; if ( $animeStats->fill($entry->mal_id) ) { # Only save if no error $animeStats->save(); $stats_counter++; + } else { + $failure++; + } + + if ( 3 < $failure ) { + echo "Got " . $failure . " failures. Returning...\n"; + return; } # sleep to avoid 403 @@ -346,4 +354,28 @@ class Background { } } + public function checkImage(Anime $anime = null) { + if ( is_null($anime) ) { + $anime = Anime::where('season_year', '=', date("Y")) + ->orWhere('season_year', '=', date("Y")-1) + ->orWhereNull('season_year')->get(); + } + $count = 0; + foreach( $anime as $entry ) { + $count++; + $fill = new Anime; + $fill->fill( $entry->mal_id, $skip_if_unpopular=false ); # check every anime we have, even with less than 10k members + + if ( $fill->image_url != $entry->image_url ) { + echo "Image URL (" . $entry->mal_id . ", " . $entry->title_pref . ") changed from " . $entry->image_url . " to " . $fill->image_url . "\n"; + DB::table('anime') + ->where('mal_id', $fill->mal_id) + ->update(['image_url' => $fill->image_url]); + } + sleep(1); + } + + echo $count; + } + } |
