diff options
| author | horus | 2020-09-17 23:37:00 +0200 |
|---|---|---|
| committer | horus | 2020-09-17 23:37:00 +0200 |
| commit | 0c521f4907ee74cda8d4b6810a5ccb21c175f857 (patch) | |
| tree | 4c334a83f6281d0f23deb35077157811eae3ab16 /app/Libraries/Background.php | |
| parent | 0e3b6263b4756ad93bb619ec34b7b121b87a097f (diff) | |
| download | senpai-0c521f4907ee74cda8d4b6810a5ccb21c175f857.tar.gz | |
add season to anime model
Diffstat (limited to 'app/Libraries/Background.php')
| -rw-r--r-- | app/Libraries/Background.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index b23e519..50efe9b 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -296,4 +296,50 @@ class Background { return true; } + public function addSeasonToAllAnime() { + $jikan = new Malclient; + + foreach( Anime::where('airing_status', '!=', env('ANIME_NOT_YET_AIRED'))->where( + function($q){ $q->where('season_name', '=', '')->orWhereNull('season_name'); } + )->get() as $anime ) + { + + try { + $animeInfo = $jikan->getAnime( + (new \Jikan\Request\Anime\AnimeRequest( $anime->mal_id )) + ); + } catch (\Exception $e) { + echo "addSeasonToAllAnime(): Problem requesting AnimeInfo for (" . $anime->mal_id . ") continue\n"; + echo $e->getMessage(); + echo "\n\n"; + sleep(10); + continue; + } + + echo "Going to update " . $animeInfo->getTitle() . " ( " . $anime->mal_id . ")\n"; + + if ( is_null( $animeInfo->getPremiered() ) ) { + $tmp_date = getSeasonFromDate( $animeInfo->getAired()->getFrom() ); + + $season_name = $tmp_date["name"]; + $season_year = $tmp_date["year"]; + } else { + $season_name = explode(" ", $animeInfo->getPremiered())[0]; + $season_year = explode(" ", $animeInfo->getPremiered())[1]; + } + + DB::table('anime') + ->where('mal_id', $anime->mal_id) + ->update([ + 'season_name' => $season_name, + 'season_year' => $season_year, + ]); + + echo "Updated " . $animeInfo->getTitle() . " to " . $season_name . " " . $season_year . ".\n"; + + + sleep(5); + } + } + } |
