diff options
| author | horus | 2020-09-23 16:43:00 +0200 |
|---|---|---|
| committer | horus | 2020-09-23 16:43:00 +0200 |
| commit | 92c77557fcb3f50138d878a62e83d36997424d9e (patch) | |
| tree | 6796959d8a433077c2376259ae35330979f37cc3 | |
| parent | b2f1970612d3312eac35f3a2854d40d44a680073 (diff) | |
| download | senpai-92c77557fcb3f50138d878a62e83d36997424d9e.tar.gz | |
cut verbosity and check for broken things
| -rw-r--r-- | app/Console/Kernel.php | 13 | ||||
| -rw-r--r-- | app/Libraries/Background.php | 32 |
2 files changed, 42 insertions, 3 deletions
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ee6ae61..35eb4e4 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -75,6 +75,12 @@ class Kernel extends ConsoleKernel echo "addSeasonToAllAnime()\n"; $background->addSeasonToAllAnime(); })->weeklyOn(1, '15:30')->name('saveTopAnime')->withoutOverlapping(); + + $schedule->call( function(){ + $background = new Background(); + echo "checkImage()\n"; + $background->checkImage(); + })->weeklyOn(3, '18:00')->name('checkForBrokenThings')->withoutOverlapping(); #})->everyMinute(); /* @@ -94,11 +100,12 @@ class Kernel extends ConsoleKernel $schedule->call( function(){ $background = new Background(); #$background->checkIfIsAiring(); - $background->saveTopAnimeByPopularity(); + $background->checkImage(); + #$background->saveTopAnimeByPopularity(); #$anime = Anime::where('mal_id', 40591)->get()->first(); #$background->saveAiring( $anime ); - #})->everyMinute()->name('saveTopAnime2')->withoutOverlapping(); - })->dailyAt('3:00')->name('saveTopAnimeByPopularity')->withoutOverlapping(); + })->everyMinute()->name('c4')->withoutOverlapping(); + #})->dailyAt('3:00')->name('saveTopAnimeByPopularity')->withoutOverlapping(); #})->everyMinute()->name('saveTopAnimeByPopularity2')->withoutOverlapping(); */ } 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; + } + } |
