diff --git a/app/Console/Commands/Grapper/Sofascore.php b/app/Console/Commands/Grapper/Sofascore.php index ba795906..7035539c 100644 --- a/app/Console/Commands/Grapper/Sofascore.php +++ b/app/Console/Commands/Grapper/Sofascore.php @@ -16,10 +16,14 @@ ini_set('magic_quotes_runtime', false); class Sofascore { + public static string $storage; + public static function switch() { $function = Nuh::$options['fun']; + self::$storage = storage_path('sofascore_data'); + switch ($function) { case 1: PlayerPerSeason::run(); @@ -28,23 +32,23 @@ class Sofascore SettingsToLocal::run(); break; case 3: - CreateZip::run(); - break; - case 4: - SendMail::run(); - break; - case 5: - DaysTournament::run(); - break; - case 6: - Grapper::load(); - break; - case 7: TaskConfig::start(); break; - case 8: + case 4: + DaysTournament::run(); + break; + case 5: + Grapper::load(); + break; + case 6: TaskConfig::end(); break; + case 7: + CreateZip::run(); + break; + case 8: + SendMail::run(); + break; default: Notice::note('id not valid', 'br', 1); diff --git a/app/Console/Commands/Grapper/Sofascore/CreateZip.php b/app/Console/Commands/Grapper/Sofascore/CreateZip.php index 0a6e569f..b53d1ccb 100644 --- a/app/Console/Commands/Grapper/Sofascore/CreateZip.php +++ b/app/Console/Commands/Grapper/Sofascore/CreateZip.php @@ -14,7 +14,7 @@ class CreateZip $debug = Nuh::$options['d'] ?? 0; $days = LoadDays::load(); - + foreach ($days as $d) { $day = $d['day']; @@ -23,7 +23,7 @@ class CreateZip } if ($debug) { - Notice::note(\count($days).' days as zip created', 'bb'); + Notice::note('zips created', 'bb'); } } } diff --git a/app/Console/Commands/Grapper/Sofascore/DaysTournament.php b/app/Console/Commands/Grapper/Sofascore/DaysTournament.php index 9bf6c012..c5100b11 100644 --- a/app/Console/Commands/Grapper/Sofascore/DaysTournament.php +++ b/app/Console/Commands/Grapper/Sofascore/DaysTournament.php @@ -33,7 +33,7 @@ class DaysTournament if ($has) { if ($debug) { - Notice::note("All tournament for $day have been allready grapped", 'r'); + Notice::note("All tournament for $day have been allready grapped", 'g'); } } else { diff --git a/app/Console/Commands/Grapper/Sofascore/Grapper.php b/app/Console/Commands/Grapper/Sofascore/Grapper.php index 995dbfe6..6cad57eb 100644 --- a/app/Console/Commands/Grapper/Sofascore/Grapper.php +++ b/app/Console/Commands/Grapper/Sofascore/Grapper.php @@ -2,6 +2,7 @@ namespace App\Console\Commands\Grapper\Sofascore; +use App\Console\Commands\Grapper\Sofascore; use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa; use App\Console\Commands\Grapper\Sofascore\Helper\LoadDays; use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper; @@ -15,17 +16,15 @@ use Illuminate\Support\Facades\File; class Grapper { + + /** + * last 3 days = task 1 + * + * nuh --d --f 67 --fun=6 --task=1 + */ + public static function load() { - /** - * yesterday - * - * nuh --d --f 67 --fun=6 --task=1 - * - * 1783710000 - * 10 July 2026 09:00:00 PM CEST - */ - $debug = Nuh::$options['d'] ?? 0; $force = Nuh::$options['f'] ?? 0; @@ -38,6 +37,15 @@ class Grapper // dd($active_tournaments->toArray()); + + /** + * empty grapping folder + * empty mailing text + */ + // File::cleanDirectory(Sofascore::$storage); dd('clead dir'); + + SofaScoreEventGrapped::query()->update(['in_current_grapper' => false]); + foreach ($active_tournaments as $tournament) { if ($debug) { @@ -61,8 +69,6 @@ class Grapper $data = CurlSofa::load($url); - // dd($data); - Nuh::$options['s'] = 0; Nuh::$options['r'] = 0; @@ -72,15 +78,25 @@ class Grapper foreach ($data['events'] as $event) { $now = Carbon::now()->subHours(4); - $starttime = Carbon::createFromTimestamp($event->startTimestamp); + $starttime = Carbon::createFromTimestamp($event['startTimestamp']); if ($now->greaterThan($starttime)) { - $event_grapped = SofaScoreEventGrapped::where('id', $event['id'])->first(); - $event_grapped['name'] = $event->homeTeam['name'] . ' vs ' . $event->awayTeam['name']; - $event_grapped['url'] = $url; + Sleeper::rand(); - $folder = storage_path('sofascore_data') . $day . '/' . $event['tournament']['slug'] . '/' . $event['slug']; + if ($debug) { + Notice::note($day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'bg'); + } + + $grapped = SofaScoreEventGrapped::firstOrNew(['id' => $event['id']]); + $grapped->day = $day; + $grapped->liga = $event['tournament']['name']; + $grapped->name = $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name']; + $grapped->url = $url; + $grapped->starttime = $starttime->toDateTimeString(); + $grapped->in_current_grapper = true; + + $folder = Sofascore::$storage . '/' . $day . '/' . $event['tournament']['slug'] . '/' . $event['slug']; File::makeDirectory($folder, 0775, true, true); @@ -96,77 +112,79 @@ class Grapper $event_id = $event['id']; - if ($force || !$event_grapped['got_statistics'] && $event->hasEventPlayerStatistics) { + // if (!$grapped['got_statistics'] && isset($event['hasEventPlayerStatistics']) && $event['hasEventPlayerStatistics'] == true) { - $url = Nuh::$options['base_url'] . "api/v1/event/$event_id/statistics"; + $url = Nuh::$options['base_url'] . "api/v1/event/$event_id/statistics"; - Sleeper::rand(); + Sleeper::rand(); - $data = CurlSofa::load($url); + $data = CurlSofa::load($url); - $data['id'] = $event_id; + $data['id'] = $event_id; - File::put($folder . '/statistics.json', json_encode($data)); + File::put($folder . '/statistics.json', json_encode($data)); - $event_grapped['got_statistics'] = 1; - } + $grapped->got_statistics = 1; + // } /********************************* * EVENT lineups *********************************/ - if ($force || !$event_grapped['got_lineups']) { + // if (!$grapped['got_lineups']) { - $url = Nuh::$options['base_url'] . "api/v1/event/$event_id/lineups"; + $url = Nuh::$options['base_url'] . "api/v1/event/$event_id/lineups"; - Sleeper::rand(); + Sleeper::rand(); - $data = CurlSofa::load($url); + $data = CurlSofa::load($url); - $data['id'] = $event_id; + $data['id'] = $event_id; - File::put($folder . '/lineups.json', json_encode($data)); + File::put($folder . '/lineups.json', json_encode($data)); - $event_grapped['got_lineups'] = 1; - } + $grapped->got_lineups = 1; + // } /********************************* * EVENT odds *********************************/ - if ($force || !$event_grapped['got_odds']) { + // if (!$grapped['got_odds']) { - $url = Nuh::$options['base_url'] . "api/v1/event/$event_id/odds/1/all"; + $url = Nuh::$options['base_url'] . "api/v1/event/$event_id/odds/1/all"; - Sleeper::rand(); + Sleeper::rand(); - $data = CurlSofa::load($url); + $data = CurlSofa::load($url); - $data['id'] = $event_id; + $data['id'] = $event_id; - File::put($folder . '/odds.json', json_encode($data)); + File::put($folder . '/odds.json', json_encode($data)); - $event_grapped['got_odds'] = 1; - } + $grapped->got_odds = 1; + // } /********************************* * EVENT incidents *********************************/ - if ($force || !$event_grapped['got_incidents']) { + // if (!$grapped['got_incidents']) { - $url = Nuh::$options['base_url'] . "api/v1/event/$event_id/incidents"; + $url = Nuh::$options['base_url'] . "api/v1/event/$event_id/incidents"; - Sleeper::rand(); + Sleeper::rand(); - $data = CurlSofa::load($url); + $data = CurlSofa::load($url); - $data['id'] = $event_id; + $data['id'] = $event_id; - File::put($folder . '/incidents.json', json_encode($data)); + File::put($folder . '/incidents.json', json_encode($data)); - $event_grapped['got_incidents'] = 1; - } + $grapped->got_incidents = 1; + // } + + $grapped->save(); } } } diff --git a/app/Console/Commands/Grapper/Sofascore/Helper/Sleeper.php b/app/Console/Commands/Grapper/Sofascore/Helper/Sleeper.php index 4bdb858c..3df96650 100644 --- a/app/Console/Commands/Grapper/Sofascore/Helper/Sleeper.php +++ b/app/Console/Commands/Grapper/Sofascore/Helper/Sleeper.php @@ -9,7 +9,7 @@ class Sleeper if ($langsam) { $sleep = rand(3000000, 6000000); } else { - $sleep = rand(500000, 100000); + $sleep = rand(100000, 150000); } usleep($sleep); } diff --git a/app/Console/Commands/Grapper/Sofascore/SendMail.php b/app/Console/Commands/Grapper/Sofascore/SendMail.php index 55fea026..c8480300 100644 --- a/app/Console/Commands/Grapper/Sofascore/SendMail.php +++ b/app/Console/Commands/Grapper/Sofascore/SendMail.php @@ -2,8 +2,11 @@ namespace App\Console\Commands\Grapper\Sofascore; +use App\Console\Commands\Grapper\Sofascore; use App\Console\Commands\Grapper\Sofascore\Helper\LoadDays; use App\Console\Commands\Nuh; +use App\Mail\SofaScoreDataMail; +use App\Models\SofaScoreEventGrapped; use App\Utilities\Notice; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Mail; @@ -20,25 +23,20 @@ class SendMail $day = $d['day']; - $zip_file = storage_path('sofascore_data') . '/' . $day . '.zip'; + $message = self::createMailText($day); + + $zip_file = Sofascore::$storage . '/' . $day . '.zip'; if (File::exists($zip_file)) { + Mail::to('hermann.telser@gmail.com') + ->cc('ubaldo.perrucci@gmail.com') + ->send( + new SofaScoreDataMail($day, $message, $zip_file) + ); if ($debug) { Notice::note('Mail send' . $day); } - - - Mail::send([], [], function ($message) use ($day, $zip_file) { - - $message->to('hermann.telser@gmail.com', 'sofa archive ' . $day) - ->cc('ubaldo.perrucci@gmail.com', 'sofa archive ' . $day) - ->subject("sofa archive $day") - ->attach($zip_file, [ - 'mime' => 'application/x-zip-compressed', - 'as' => 'sofa archive ' . $day . '.zip', - ]); - }); } } @@ -46,4 +44,16 @@ class SendMail Notice::note('Mail send', 'g'); } } + + public static function createMailText(string $day) + { + $res = SofaScoreEventGrapped::where('day', $day)->get(); + $text = "## Mail Content $day + "; + foreach ($res as $value) { + $text .= "### $value->liga * $value->name * $value->starttime + "; + } + return $text; + } } diff --git a/app/Mail/SofaScoreDataMail.php b/app/Mail/SofaScoreDataMail.php new file mode 100644 index 00000000..9d39074c --- /dev/null +++ b/app/Mail/SofaScoreDataMail.php @@ -0,0 +1,62 @@ +day = $day; + $this->message = $message; + $this->zip_file = $zip_file; + } + + /** + * Get the message envelope. + */ + public function envelope(): Envelope + { + return new Envelope( + subject: 'Sofa Score ' . $this->day, + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + markdown: 'mail.user.sofascore_data', + with: [ + 'message' => $this->message, + ], + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return [ + Attachment::fromPath($this->zip_file) + ->as('sofa archive ' . $this->day . '.zip') + ->withMime('application/x-zip-compressed') + ]; + } +} diff --git a/app/Utilities/ZipFolder.php b/app/Utilities/ZipFolder.php index f4f501bb..f8d4c6f9 100644 --- a/app/Utilities/ZipFolder.php +++ b/app/Utilities/ZipFolder.php @@ -2,6 +2,7 @@ namespace App\Utilities; +use App\Console\Commands\Grapper\Sofascore; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use ZipArchive; @@ -11,9 +12,9 @@ class ZipFolder public static function create(string $day) { - $zipFilePath = storage_path('sofascore_data') . '/' . $day . '.zip'; + $zipFilePath = Sofascore::$storage . '/' . $day . '.zip'; - $path = storage_path('sofascore_data') . $day; + $path = Sofascore::$storage . '/' . $day; $zip = new ZipArchive(); diff --git a/apple_damon.sh b/apple_damon.sh index 1d95aa80..d44dffbb 100755 --- a/apple_damon.sh +++ b/apple_damon.sh @@ -21,28 +21,28 @@ case "$1" in echo "\n⚽ open vpn" ssh -f -N -L 13306:127.0.0.1:3306 -p 58371 root@162.55.242.190 - echo "\n⚽ copy settings" + echo "\n⚽ SettingsToLocal" php artisan nuh --d --f 67 --fun=2 --task=$1 echo "\n⚽ close vpn" killall ssh - echo "\n⚽ start task" - php artisan nuh --d --f 67 --fun=7 --task=$1 - - echo "\n⚽ get tournaments for the day" - php artisan nuh --d --f 67 --fun=5 --task=$1 - - echo "\n⚽ grapper events for the day" - php artisan nuh --d --f 67 --fun=6 --task=$1 - - echo "\n⚽ create zip archive" + echo "\n⚽ TaskConfig start" php artisan nuh --d --f 67 --fun=3 --task=$1 - echo "\n⚽ mail archive" + echo "\n⚽ DaysTournament" php artisan nuh --d --f 67 --fun=4 --task=$1 - echo "\n⚽ end task" + echo "\n⚽ Grapper" + php artisan nuh --d --f 67 --fun=5 --task=$1 + + echo "\n⚽ TaskConfig end" + php artisan nuh --d --f 67 --fun=6 --task=$1 + + echo "\n⚽ CreateZip" + php artisan nuh --d --f 67 --fun=7 --task=$1 + + echo "\n⚽ SendMail" php artisan nuh --d --f 67 --fun=8 --task=$1 echo "\n😎 done :)" diff --git a/database/migrations/2026_07_11_145940_create_sofa_score_event_grappeds_table.php b/database/migrations/2026_07_11_145940_create_sofa_score_event_grappeds_table.php index ae0326e3..f9f85850 100644 --- a/database/migrations/2026_07_11_145940_create_sofa_score_event_grappeds_table.php +++ b/database/migrations/2026_07_11_145940_create_sofa_score_event_grappeds_table.php @@ -13,9 +13,12 @@ return new class extends Migration { Schema::create('sofa_score_event_grappeds', function (Blueprint $table) { $table->id(); + $table->date('day')->nullable(); + $table->string('liga')->nullable(); $table->string('name')->nullable(); - $table->string('url')->nullable(); $table->dateTime('starttime')->nullable(); + $table->string('url')->nullable(); + $table->boolean('in_current_grapper')->default(false); $table->boolean('got_statistics')->default(false); $table->boolean('got_lineups')->default(false); $table->boolean('got_odds')->default(false); diff --git a/resources/views/mail/user/sofascore_data.blade.php b/resources/views/mail/user/sofascore_data.blade.php new file mode 100644 index 00000000..6c070f1d --- /dev/null +++ b/resources/views/mail/user/sofascore_data.blade.php @@ -0,0 +1,3 @@ + + {{ $message }} + \ No newline at end of file diff --git a/resources/views/vendor/mail/html/header.blade.php b/resources/views/vendor/mail/html/header.blade.php index 8b44ed75..aef92eb9 100644 --- a/resources/views/vendor/mail/html/header.blade.php +++ b/resources/views/vendor/mail/html/header.blade.php @@ -1,21 +1,22 @@ - -
- -
-{!! $slot !!} -
- - + +
+ + + + + + + + + + + + + + +
+ {!! $slot !!} +
+ + \ No newline at end of file diff --git a/resources/views/vendor/mail/html/message.blade.php b/resources/views/vendor/mail/html/message.blade.php index a16bace0..68e28654 100644 --- a/resources/views/vendor/mail/html/message.blade.php +++ b/resources/views/vendor/mail/html/message.blade.php @@ -1,27 +1,27 @@ -{{-- Header --}} - - -{{ config('app.name') }} - - + {{-- Header --}} + + + by New-Odds Market Monitoring + + -{{-- Body --}} -{!! $slot !!} + {{-- Body --}} + {!! $slot !!} -{{-- Subcopy --}} -@isset($subcopy) - - -{!! $subcopy !!} - - -@endisset + {{-- Subcopy --}} + @isset($subcopy) + + + {!! $subcopy !!} + + + @endisset -{{-- Footer --}} - - -© {{ date('Y') }} {{ config('app.name') }}. {{ __('All rights reserved.') }} - - - + {{-- Footer --}} + + + © {{ date('Y') }} NUH-Odds GmbH Innsbruck Austria, {{ __('All rights reserved.') }} + + + \ No newline at end of file