diff options
Diffstat (limited to 'app/Libraries')
| -rw-r--r-- | app/Libraries/Background.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index 794ca02..91d9d75 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -10,6 +10,7 @@ use App\Libraries\AnimeSchedule; use App\Libraries\AnimeSeason; use App\Anime; use App\AnimeStats; +use App\AnimeDetails; use App\MALUser; use App\Calendar; use App\Airing; @@ -144,6 +145,7 @@ class Background { $failure = 0; 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(); @@ -168,6 +170,33 @@ class Background { return; } + $animeDetail = AnimeDetails::where('mal_id', $entry->mal_id); + + if ( ! $animeDetail->exists() ) { + + $model_score_begin = $entry->getStats()->whereNotNull('score')->orderBy('created_at', 'ASC')->limit(1)->get()->first(); + if ( ! is_null($model_score_begin) ) { + $score_begin = $model_score_begin->score; + } else { + $score_begin = null; + } + + $animeDetail->insert([ + "mal_id" => $animeStats->mal_id, + "score_begin" => $score_begin, + "score_today" => $animeStats->score, + "watching" => $animeStats->watching, + "members" => $animeStats->members + ]); + } else { + $animeDetail->update([ + "mal_id" => $animeStats->mal_id, + "score_today" => $animeStats->score, + "watching" => $animeStats->watching, + "members" => $animeStats->members + ]); + } + # sleep to avoid 403 sleep(5); } |
