summaryrefslogtreecommitdiff
path: root/app/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'app/Libraries')
-rw-r--r--app/Libraries/Background.php46
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);
+ }
+ }
+
}