diff options
| -rw-r--r-- | app/Console/Kernel.php | 16 | ||||
| -rw-r--r-- | app/Http/Controllers/AnimeController.php | 19 | ||||
| -rw-r--r-- | app/Libraries/Background.php | 76 | ||||
| -rw-r--r-- | app/helpers.php | 17 | ||||
| -rw-r--r-- | resources/views/index_anime.blade.php | 27 | ||||
| -rw-r--r-- | resources/views/surprising_anime.blade.php | 31 | ||||
| -rw-r--r-- | resources/views/top_anime.blade.php | 29 | ||||
| -rw-r--r-- | routes/web.php | 2 |
8 files changed, 165 insertions, 52 deletions
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 8582678..7663b67 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -37,7 +37,9 @@ class Kernel extends ConsoleKernel $background = new Background(); $background->saveAnimeStats(); })->everyThirtyMinutes()->name('saveStats')->withoutOverlapping(); - #})->everyMinute(); + #})->everyThirtyMinutes()->name('saveStats5')->withoutOverlapping(); + #})->everyMinute()->name('saveStats3')->withoutOverlapping(); + #})->everyMinute()->name('saveStats5')->withoutOverlapping(); $schedule->call( function(){ $background = new Background(); @@ -64,6 +66,8 @@ class Kernel extends ConsoleKernel $schedule->call( function(){ $background = new Background(); + echo "saveTopAnime()"; + $background->saveTopAnime(); echo"saveEnhancementForAll()\n"; $background->saveEnhancementForAll(); })->weeklyOn(1, '15:30'); @@ -79,6 +83,16 @@ class Kernel extends ConsoleKernel })->everyMinute(); #})->twiceDaily(9, 23); */ + + /* + $schedule->call( function(){ + $background = new Background(); + #$background->checkIfIsAiring(); + $background->saveTopAnime(); + #$anime = Anime::where('mal_id', 40591)->get()->first(); + #$background->saveAiring( $anime ); + })->everyMinute()->name('saveTopAnime2')->withoutOverlapping(); + */ } /** diff --git a/app/Http/Controllers/AnimeController.php b/app/Http/Controllers/AnimeController.php index 461b583..1dd7c35 100644 --- a/app/Http/Controllers/AnimeController.php +++ b/app/Http/Controllers/AnimeController.php @@ -98,6 +98,8 @@ class AnimeController extends Controller { #$anime = $anime->setTable('anime'); $anime = $anime->where('airing_status', env('ANIME_IS_AIRING')); + $anime = $anime->orderBy('season_year', 'desc'); + $anime = $anime->orderByRaw('FIELD(season_name, "Summer", "Fall", "Winter", "Spring")'); $anime = $anime->orderBy('watching', 'desc'); $anime = $anime->orderBy('members', 'desc'); $anime = $anime->orderBy('score_today', 'desc'); @@ -105,4 +107,21 @@ class AnimeController extends Controller { return view('index_anime', ["all_anime" => $anime, "most_suprising_anime" => $most_surprising_anime]); } + + public function showSurprisingAnime() { + $anime = new Anime; + $most_surprising_anime = $anime->setTable('view_anime_index'); + $most_surprising_anime = $most_surprising_anime->simplePaginate(10); + + return view('surprising_anime', ["surprising_anime" => $most_surprising_anime]); + } + + public function showTopAnime() { + $anime = new Anime; + $anime = $anime->setTable('view_anime_index'); + $anime = $anime->orderBy('score_today', 'desc'); + $top_anime = $anime->simplePaginate(10); + + return view('top_anime', ["top_anime" => $top_anime]); + } } diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index 9c9f336..8cfe9e1 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -126,31 +126,9 @@ class Background { sleep(10); foreach($season->anime as $entry) { - if ( Anime::where('mal_id', $entry->getMalID())->exists() ) { - /** - * We already have this anime saved. - */ - echo "saveSeason: Duplicate entry: (" . $entry->getMalID() . ") Continue\n"; - continue; - } - - $anime = new Anime(); - /** - * Sleep to avoid 403 by MAL. - */ - sleep(10); - $anime->fill( $entry->getMalID() ); - - if ( "" == $anime->url ) { - echo "saveSeason: url is empty for: " . $entry->getMalId() . "\n"; - continue; - } - - if( ! DB::table('anime')->where('mal_id', $entry->getMalID() )->exists() ) { - $anime->save(); - } - sleep(10); + $this->saveAnime($entry); + sleep(10); } } @@ -245,4 +223,54 @@ class Background { sleep(1); } } + + public function saveTopAnime() { + $jikan = new MalClient; + + for ( $page = 1; $page <= 10; $page++) { + $topAnime = $jikan->getTopAnime( + (new \Jikan\Request\Top\TopAnimeRequest($page)) + ); + + sleep(5); + foreach ( $topAnime as $anime) { + if ( $this->saveAnime($anime) ) { + echo "saveTopAnime: Saved (" . $anime->getMalId() . ")\n"; + } + sleep(5); + } + } + + } + + private function saveAnime($entry, $caller = "saveAnime") { + if ( Anime::where('mal_id', $entry->getMalID())->exists() ) { + /** + * We already have this anime saved. + */ + echo $caller . ": Duplicate entry: (" . $entry->getMalID() . ") Continue\n"; + + return false; + } + + $anime = new Anime(); + + /** + * Sleep to avoid 403 by MAL. + */ + $anime->fill( $entry->getMalID() ); + + if ( "" == $anime->url ) { + echo $caller . ": url is empty for: " . $entry->getMalId() . "\n"; + + return false; + } + + if( ! DB::table('anime')->where('mal_id', $entry->getMalID() )->exists() ) { + $anime->save(); + } + + return true; + } + } diff --git a/app/helpers.php b/app/helpers.php index 7ac1fd6..9246362 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -66,3 +66,20 @@ function getAiringStatusCode($airing_status) { } return $status[0]->id; } + +function getCurrentSeason(){ + switch( date("m") ) { + case 1: + case 2: + case 3: return "Winter"; + case 4: + case 5: + case 6: return "Spring"; + case 7: + case 8: + case 9: return "Summer"; + case 10: + case 11: + case 12: return "Fall"; + } +} diff --git a/resources/views/index_anime.blade.php b/resources/views/index_anime.blade.php index 4fa6b72..2bb30de 100644 --- a/resources/views/index_anime.blade.php +++ b/resources/views/index_anime.blade.php @@ -3,33 +3,6 @@ @section('content') <div class="container" id="index"> -<h1>Most surprising anime</h1> -@foreach($most_suprising_anime as $anime) - <div class="row"> - <div class="col-sm-4 col-lg-3"> - <a href="/anime/{{ $anime->mal_id}}" title="Click for more data"> - <img src="{{ $anime->image_url }}" class="img-fluid" style="margin-bottom: 10px;"> - </a> - </div> - <div class="col-sm-8 col-lg-9"> - <h2>{{ $anime->title_pref }}</h2> - Score diff: {{ $anime->score_today - $anime->score_begin }} Points - <br> - First score: {{ $anime->score_begin }} - <br> - Score now: {{ $anime->score_today }} - <br> - <a href="/anime/{{ $anime->mal_id}}" title="Click for more data"> - Click for more data - </a> - </div> - </div> -@endforeach - -<br> -<br> -<br> -<br> <h1>Top anime this season</h1> @foreach($all_anime as $anime) <div class="row"> diff --git a/resources/views/surprising_anime.blade.php b/resources/views/surprising_anime.blade.php new file mode 100644 index 0000000..5fe0648 --- /dev/null +++ b/resources/views/surprising_anime.blade.php @@ -0,0 +1,31 @@ +@extends('layouts.app') + +@section('content') +<div class="container" id="index"> + +<h1>Most surprising anime</h1> +@foreach($surprising_anime as $anime) + <div class="row"> + <div class="col-sm-4 col-lg-3"> + <a href="/anime/{{ $anime->mal_id}}" title="Click for more data"> + <img src="{{ $anime->image_url }}" class="img-fluid" style="margin-bottom: 10px;"> + </a> + </div> + <div class="col-sm-8 col-lg-9"> + <h2>{{ $anime->title_pref }}</h2> + Score diff: {{ $anime->score_today - $anime->score_begin }} Points + <br> + First score: {{ $anime->score_begin }} + <br> + Score now: {{ $anime->score_today }} + <br> + <a href="/anime/{{ $anime->mal_id}}" title="Click for more data"> + Click for more data + </a> + </div> + </div> +@endforeach + +{{ $surprising_anime ->links() }} +</div> +@endsection diff --git a/resources/views/top_anime.blade.php b/resources/views/top_anime.blade.php new file mode 100644 index 0000000..3ffea89 --- /dev/null +++ b/resources/views/top_anime.blade.php @@ -0,0 +1,29 @@ +@extends('layouts.app') + +@section('content') +<div class="container" id="index"> + +<h1>Top Anime</h1> +@foreach($top_anime as $anime) + <div class="row"> + <div class="col-sm-4 col-lg-3"> + <a href="/anime/{{ $anime->mal_id}}" title="Click for more data"> + <img src="{{ $anime->image_url }}" class="img-fluid" style="margin-bottom: 10px;"> + </a> + </div> + <div class="col-sm-8 col-lg-9"> + <h2>{{ $anime->title_pref }}</h2> + Score: {{ $anime->score_today }} + <br> + Popularity {{ $anime->score_today }} + <br> + <a href="/anime/{{ $anime->mal_id}}" title="Click for more data"> + Click for more data + </a> + </div> + </div> +@endforeach + +{{ $top_anime->links() }} +</div> +@endsection diff --git a/routes/web.php b/routes/web.php index 6ab6f19..8244ce6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -18,6 +18,8 @@ Route::get('/save', 'IndexController@saveWatchingAnime'); Route::get('/test/getcal/{username}', 'TestController@getCalendar'); Route::get('/test/setcal/{username}', 'TestController@setCalendar'); Route::get('/api/anime/{mal_id}', 'ApiController@getAnime'); +Route::get('/anime/surprising/', 'AnimeController@showSurprisingAnime')->name('surprising_anime'); +Route::get('/anime/top/', 'AnimeController@showTopAnime')->name('top_anime'); Route::get('/anime/{mal_id}/{slug?}', 'AnimeController@showAnime')->name('anime'); Route::get('/anime/', 'AnimeController@showAllAnime')->name('anime_index'); |
