diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/Console/Kernel.php | 15 | ||||
| -rw-r--r-- | app/Http/Controllers/AnimeController.php | 69 | ||||
| -rw-r--r-- | app/Libraries/Background.php | 29 | ||||
| -rw-r--r-- | app/helpers.php | 19 |
4 files changed, 111 insertions, 21 deletions
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7663b67..dc671fd 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -68,19 +68,22 @@ class Kernel extends ConsoleKernel $background = new Background(); echo "saveTopAnime()"; $background->saveTopAnime(); + echo "saveTopAnimeByPopularity()"; + $background->saveTopAnimeByPopularity(); echo"saveEnhancementForAll()\n"; $background->saveEnhancementForAll(); - })->weeklyOn(1, '15:30'); + })->weeklyOn(1, '15:30')->name('saveTopAnime')->withoutOverlapping(); #})->everyMinute(); /* $schedule->call( function(){ $background = new Background(); #$background->checkIfIsAiring(); - $background->saveSeason(); + #$background->saveSeason(); + $background->saveEnhancementForAll(); #$anime = Anime::where('mal_id', 40591)->get()->first(); #$background->saveAiring( $anime ); - })->everyMinute(); + })->everyMinute()->name("enhance")->withoutOverlapping(); #})->twiceDaily(9, 23); */ @@ -88,10 +91,12 @@ class Kernel extends ConsoleKernel $schedule->call( function(){ $background = new Background(); #$background->checkIfIsAiring(); - $background->saveTopAnime(); + $background->saveTopAnimeByPopularity(); #$anime = Anime::where('mal_id', 40591)->get()->first(); #$background->saveAiring( $anime ); - })->everyMinute()->name('saveTopAnime2')->withoutOverlapping(); + #})->everyMinute()->name('saveTopAnime2')->withoutOverlapping(); + })->dailyAt('3:00')->name('saveTopAnimeByPopularity')->withoutOverlapping(); + #})->everyMinute()->name('saveTopAnimeByPopularity2')->withoutOverlapping(); */ } diff --git a/app/Http/Controllers/AnimeController.php b/app/Http/Controllers/AnimeController.php index 1dd7c35..1a0809f 100644 --- a/app/Http/Controllers/AnimeController.php +++ b/app/Http/Controllers/AnimeController.php @@ -35,9 +35,12 @@ class AnimeController extends Controller { $anime["stats"] = $anime->getStats()->orderBy('created_at', 'asc')->get(); foreach( $anime["stats"] as $stats ) { - $score[] = $stats->score; + if ( ! is_null($stats->score) ) { + $score[] = $stats->score; + $rank[] = $stats->rank; + $created_at_score[] = $stats->created_at->toDateString(); + } $created_at[] = $stats->created_at->toDateString(); - $rank[] = $stats->rank; $popularity[] = $stats->popularity; $members[] = $stats->members; $favorites[] = $stats->favorites; @@ -85,43 +88,83 @@ class AnimeController extends Controller { $anime["score_10"] = $score_10; $anime["chart_label"] = $created_at; + $anime["chart_label_score"] = $created_at_score; $anime["basic_data"] = DB::select('select score, rank, popularity, members, favorites from anime join stats on stats.id = ( select id from stats where anime.mal_id = stats.mal_id order by created_at desc limit 1) where anime.mal_id = ?', [$mal_id])[0]; return view('anime', [ "anime" => $anime ]); } - public function showAllAnime() { + public function showCurrentAnime() { $anime = new Anime; - $most_surprising_anime = $anime->setTable('view_anime_index'); - $most_surprising_anime = $most_surprising_anime->simplePaginate(10); + $anime = $anime->setTable('view_anime_index'); + $most_surprising_anime = $anime->simplePaginate(10); #$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'); - $anime = $anime->simplePaginate(10); + $anime = $anime->orderBy('members', 'desc'); + $anime = $anime->orderBy('watching', 'desc'); + $anime = $anime->get(); + #$anime = $anime->simplePaginate(10); - return view('index_anime', ["all_anime" => $anime, "most_suprising_anime" => $most_surprising_anime]); + return view('list_anime', ["all_anime" => $anime, "most_suprising_anime" => $most_surprising_anime, "title" => "Currently Airing"]); } public function showSurprisingAnime() { $anime = new Anime; $most_surprising_anime = $anime->setTable('view_anime_index'); - $most_surprising_anime = $most_surprising_anime->simplePaginate(10); + $most_surprising_anime = $most_surprising_anime->paginate(12); + #$most_surprising_anime = $most_surprising_anime->simplePaginate(10); + #$most_surprising_anime = $most_surprising_anime->get(); - return view('surprising_anime', ["surprising_anime" => $most_surprising_anime]); + #return view('surprising_anime', ["surprising_anime" => $most_surprising_anime, "title" => "Most Surprising"]); + return view('list_anime', ["all_anime" => $most_surprising_anime, "title" => "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); + #$top_anime = $anime->simplePaginate(10); + #$top_anime = $anime->get(); + $top_anime = $anime->paginate(12); + + #return view('top_anime', ["top_anime" => $top_anime, "title" => "Top"]); + return view('list_anime', ["all_anime" => $top_anime, "title" => "Top Anime of all Time"]); + } + + public function search(Request $request) { + $search_unsafe = explode(",", $request->input("q")); + + $anime = new Anime; + $anime = $anime->setTable('view_anime_index'); + + foreach($search_unsafe as $q) { + $q_raw = escapeLike($q); + $q = "%".$q_raw."%"; + /* + $anime = $anime->where('title_eng', 'like', $q) + ->orWhere('title_rom', 'like', $q) + ->orWhere('title_nat', 'like', $q) + ->orWhere('title_pref', 'like', $q) + ->orWhere('synopsis', 'like', $q); + */ + $anime = $anime->where('title_eng', 'like', $q) + ->orWhere('mal_id', '=', $q_raw) + ->orWhere('title_pref', 'like', $q) + ->orWhere('synopsis', 'like', $q); + } + $count = $anime->count(); + $anime = $anime->orderBy('season_year', 'desc'); + $anime = $anime->orderByRaw('FIELD(season_name, "Summer", "Fall", "Winter", "Spring")'); + $anime = $anime->orderBy('score_today', 'desc'); + $anime = $anime->orderBy('members', 'desc'); + $anime = $anime->orderBy('watching', 'desc'); + $sanime = $anime->paginate(12); - return view('top_anime', ["top_anime" => $top_anime]); + return view('list_anime', ["all_anime" => $sanime, "title" => "Search", "count" => $count]); } } diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index 8cfe9e1..b23e519 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\DB; use Carbon\Carbon; use Jikan\MyAnimeList\MalClient; +use Jikan\Helper\Constants; use App\Libraries\AnimeSchedule; use App\Libraries\AnimeSeason; @@ -217,17 +218,18 @@ class Background { } public function saveEnhancementForAll() { - $anime_all = Anime::where('airing_status', env('ANIME_IS_AIRING'))->where('synopsis', '')->get(); + #$anime_all = Anime::where('airing_status', env('ANIME_IS_AIRING'))->where('synopsis', '')->get(); + $anime_all = Anime::where('synopsis', '')->get(); foreach( $anime_all as $anime ) { $this->addEnhancementToAnime($anime); sleep(1); } } - public function saveTopAnime() { + public function saveTopAnime($startpage = 1, $endpage = 10) { $jikan = new MalClient; - for ( $page = 1; $page <= 10; $page++) { + for ( $page = $startpage; $page <= $endpage; $page++) { $topAnime = $jikan->getTopAnime( (new \Jikan\Request\Top\TopAnimeRequest($page)) ); @@ -243,6 +245,27 @@ class Background { } + public function saveTopAnimeByPopularity($startpage = 1, $endpage = 10) { + $jikan = new MalClient; + + for ( $page = $startpage; $page <= $endpage; $page++) { + $topAnime = $jikan->getTopAnime( + (new \Jikan\Request\Top\TopAnimeRequest( + $page, + Constants::TOP_BY_POPULARITY)) + ); + + 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() ) { /** diff --git a/app/helpers.php b/app/helpers.php index 9246362..5c65c57 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -83,3 +83,22 @@ function getCurrentSeason(){ case 12: return "Fall"; } } + +function escapeLike($string){ + $search = array('%', '_'); + $replace = array('\%', '\_'); + $string = str_replace($search, $replace, $string); + $string = explode(" ", $string); + return implode("%", $string); +} + + +function compare($str1, $str2) { + $str1 = preg_replace("/[^a-z0-9]/", '', strtolower($str1)); + $str2 = preg_replace("/[^a-z0-9]/", '', strtolower($str2)); + + if ( $str1 != $str2 ) { + return false; + } + return true; +} |
