From 75e57c66dd49c55acb29d31693ddd022032b54fb Mon Sep 17 00:00:00 2001 From: horus Date: Fri, 6 Mar 2020 01:27:13 +0100 Subject: Scheduled commands are OK. --- app/Calendar.php | 2 +- app/Console/Kernel.php | 32 +++++++++++++++++++------------- app/Http/Controllers/IndexController.php | 12 ++++++++++-- app/Libraries/Helper.php | 26 +++++++++++++++++++------- 4 files changed, 49 insertions(+), 23 deletions(-) (limited to 'app') diff --git a/app/Calendar.php b/app/Calendar.php index a42e190..9820041 100644 --- a/app/Calendar.php +++ b/app/Calendar.php @@ -15,7 +15,7 @@ class Calendar extends Model 'duration', 'episode', 'episode_watched', - 'episode_complete', + 'episodes_complete', 'score', 'score_user', ]; diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 1f24208..4e125a3 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -30,21 +30,27 @@ class Kernel extends ConsoleKernel { // $schedule->command('inspire') // ->hourly(); + + $schedule->call( function(){ + $background = new Background(); + $background->saveAnimeStats(); + })->dailyAt('23:00'); + + $schedule->call( function(){ + $background = new Background(); + $background->saveSeason(); + sleep(10); + $background->checkIfIsAiring(); + sleep(10); + $background->saveAiringForAll(); + })->dailyAt('19:00'); + $schedule->call( function(){ - #$season = new AnimeSeason(); - #$season->save(); - - #$background = new Background(); - #$background->saveSeason(); - #$background->saveAnimeStats(); - #$background->saveAiringForAll(); - $helper = new Helper(); - $helper->createUser( 'll-' ); - $helper->setIsWatching( 'll-' ); - $helper->setCalendar( 'll-' ); -#$background->checkIfIsAiring(); - }); + #$helper->createUser( 'll-' ); + $helper->setIsWatchingForAll(); + $helper->setCalendarForAll(); + })->dailyAt('18:30'); } /** diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 11e587f..3704afe 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -9,6 +9,7 @@ use App\Libraries\AnimeSeason; use App\Anime; use App\AnimeStats; use App\MALUser; +use App\Libraries\Helper; class IndexController extends Controller { /** @@ -25,8 +26,8 @@ class IndexController extends Controller { public function iCal($username) { if ( ! Cache::has('schedule_' . $username)) { - $userSchedule = new AnimeSchedule( $username ); - $schedule = $userSchedule->getCalendar(); + $helper = new Helper(); + $schedule = $helper->getCalendar($username); Cache::put('schedule_' . $username, $schedule, 360); } else { $schedule = Cache::get('schedule_' . $username); @@ -81,6 +82,13 @@ class IndexController extends Controller { } public function createUser( $username ) { + $helper = new Helper(); + $helper->createUser( $username ); + $helper->setIsWatching( $username ); + $helper->setCalendar( $username ); + echo "OK. https://animes.iamfabulous.de/ical/" . $username; + return; + $user = MALUser::where('username', $username)->get()->first(); var_dump( $user ); diff --git a/app/Libraries/Helper.php b/app/Libraries/Helper.php index 88650b4..65d774b 100644 --- a/app/Libraries/Helper.php +++ b/app/Libraries/Helper.php @@ -17,7 +17,6 @@ use Eluceo\iCal\Component\Event; class Helper { public function getCalendar( $username ) { - echo "
";
$user = MALUser::where('username', $username)->get()->first();
$vCalendar = new iCalendar('animes.iamfabulous.de');
@@ -25,10 +24,10 @@ class Helper {
foreach( $user->calendar()->get() as $anime ) {
- if ( is_null($anime->episodes_completes) ) {
+ if ( is_null($anime->episodes_complete) ) {
$episodes_complete = '?';
} else {
- $episodes_complete = $anime->episodes_completes;
+ $episodes_complete = $anime->episodes_complete;
}
$vEvent = new Event();
@@ -52,12 +51,12 @@ class Helper {
$user = MALUser::where('username', $username)->get()->first();
if ( is_null($user) ) {
- echo "User (" . $username . ") does not exists. Skipping\n";
+ echo "setCalendar: User (" . $username . ") does not exists. Skipping\n";
return;
}
if ( is_null($user->IsWatching) ) {
- echo "User (" . $username . ") does not watch any anime. Skipping\n";
+ echo "setCalendar: User (" . $username . ") does not watch any anime. Skipping\n";
return;
}
@@ -74,7 +73,7 @@ class Helper {
})->get()->first();
if ( ! is_null( $check ) ) {
- echo "duplicate entry. ".$anime->mal_id." continue\n"; continue;
+ echo "setCalendar: duplicate entry. ".$anime->mal_id." continue\n"; continue;
}
$calendar = new Calendar();
@@ -99,7 +98,7 @@ class Helper {
$user = MALUser::where('username', $username)->get()->first();
if ( is_null($user) ) {
- echo "User (" . $username . ") does not exists. Skipping\n";
+ echo "setIsWatching: User (" . $username . ") does not exists. Skipping\n";
return;
}
@@ -141,4 +140,17 @@ class Helper {
return $user;
}
+ public function setIsWatchingForAll() {
+ $users = MALUser::all();
+ foreach( $users as $user ) {
+ $this->setIsWatching( $user->username );
+ }
+ }
+ public function setCalendarForAll() {
+ $users = MALUser::all();
+ foreach( $users as $user ) {
+ $this->setCalendar( $user->username );
+ }
+ }
+
}
--
cgit v1.2.3