This commit is contained in:
salam committed 2026-07-03 10:55:55 +02:00
1 parent 75d7914a59
commit dc76eb35ae
21 files changed
+177 -178

No files matched your search

+10 -21
View File
@@ -28,13 +28,9 @@ class Sofascore
self::$storage_path = storage_path('zip_sofascore_data');
$task = Nuh::$options['task'] ?? 0;
$function = Nuh::$options['fun'];
$process = Nuh::$options['run'];
$days = LoadDays::load($task);
switch($process){
switch($function){
case 1:
PlayerPerSeason::run();
break;
@@ -42,29 +38,22 @@ class Sofascore
SettingsToLocal::run();
break;
case 3:
if($days){
CreateZip::run($days);
}
CreateZip::run();
break;
case 4:
if($days){
SendMail::run($days);
}
SendMail::run();
break;
case 5:
if($days){
DaysTournament::run($days);
}
DaysTournament::run();
break;
case 6:
if($days){
Grapper::load($days);
}
Grapper::load();
break;
case 7:
if($days){
TaskConfig::set($task);
}
TaskConfig::start();
break;
case 8:
TaskConfig::end();
break;
default:
@@ -2,15 +2,20 @@
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grapper\Sofascore\Helper\LoadDays;
use App\Console\Commands\Nuh;
use App\Utilities\Notice;
use App\Utilities\ZipFolder;
class CreateZip
{
public static function run(array $days)
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
$task = Nuh::$options['task'] ?? 0;
$days = LoadDays::load($task);
foreach ($days as $d) {
@@ -2,8 +2,9 @@
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grapper\Sofascore\CurlSofa;
use App\Console\Commands\Grapper\Sofascore\Tools\Sleeper;
use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa;
use App\Console\Commands\Grapper\Sofascore\Helper\LoadDays;
use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper;
use App\Console\Commands\Nuh;
use App\Models\Country;
use App\Models\SofaScoreCategorie;
@@ -14,10 +15,12 @@ use Illuminate\Support\Facades\Log;
class DaysTournament
{
public static function run(array $days)
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
$days = LoadDays::load();
$tournaments_counter = 0;
foreach ($days as $d) {
@@ -2,39 +2,50 @@
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;
use App\Console\Commands\Nuh;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreTournament;
use App\Models\SofaScoreTaskTournament;
use App\Utilities\Notice;
use Illuminate\Support\Facades\File;
class Grapper
{
public static function load(array $days)
public static function load()
{
$debug = Nuh::$options['d'] ?? 0;
$force = Nuh::$options['f'] ?? 0;
foreach ($days as $d) {
$task_id = Nuh::$options['task'] ?? 0;
$langsam = $d['run_slow'];
$days = LoadDays::load();
$sport_id = $d['sport_id'];
$active_tournaments = SofaScoreTaskTournament::with('tournament')->where('id', $task_id)->get();
$day = $d['day'];
foreach ($active_tournaments as $tournament) {
$active_tournaments = SofaScoreTournament::select('name', 'tournament_id')->where('sport_id', $sport_id)->where('enabled', 1)->get();
if ($debug) {
Notice::note($tournament->tournament->name, 'bg');
}
foreach ($active_tournaments as $tournament) {
foreach ($days as $d) {
$has = SofaScoreDayTournament::where('day', $day)->where('tournament_id', $tournament->tournament_id)->first();
$langsam = $d['run_slow'];
if ($has) {
$day = $d['day'];
$res = SofaScoreDayTournament::whereDate('day','=', $day)->where('tournament_id', $tournament->sofa_score_tournament_id)->first();
if($res){
if ($debug) {
Notice::note($day.' - '.$tournament->name.' grapping', 'g');
}
Notice::note($day, 'g');
}
$url = Nuh::$options['base_url']."api/v1/unique-tournament/$tournament->tournament_id/scheduled-events/$day";
$url = Nuh::$options['base_url']."api/v1/unique-tournament/$tournament->sofa_score_tournament_id/scheduled-events/$day";
Sleeper::rand($langsam);
@@ -48,9 +59,7 @@ class Grapper
foreach ($data['events'] as $event) {
Notice::note($event['season']['name'].' '.$day, 'bb');
$folder = app_path().self::$storage_path.$day.'/'.$event['tournament']['slug'].'/'.$event['slug'];
$folder = app_path().Sofascore::$storage_path.$day.'/'.$event['tournament']['slug'].'/'.$event['slug'];
File::makeDirectory($folder, 0775, true, true);
@@ -66,7 +75,7 @@ class Grapper
$event_id = $event['id'];
if(!File::file_exists($folder.'/statistics.json')){
if(!File::exists($folder.'/statistics.json') || $force){
$url = Nuh::$options['base_url']."api/v1/event/$event_id/statistics";
@@ -83,7 +92,7 @@ class Grapper
* EVENT lineups
*********************************/
if(!File::file_exists($folder.'/lineups.json')){
if(!File::exists($folder.'/lineups.json') || $force){
$url = Nuh::$options['base_url']."api/v1/event/$event_id/lineups";
@@ -100,7 +109,7 @@ class Grapper
* EVENT odds
*********************************/
if(!File::file_exists($folder.'/odds.json')){
if(!File::exists($folder.'/odds.json') || $force){
$url = Nuh::$options['base_url']."api/v1/event/$event_id/odds/1/all";
@@ -117,7 +126,7 @@ class Grapper
* EVENT incidents
*********************************/
if(!File::file_exists($folder.'/incidents.json')){
if(!File::exists($folder.'/incidents.json') || $force){
$url = Nuh::$options['base_url']."api/v1/event/$event_id/incidents";
@@ -130,10 +139,7 @@ class Grapper
File::put($folder.'/incidents.json', json_encode($data));
}
}
}
} else {
if ($debug) {
Notice::note($day.' - '.$tournament->name.' not active', 'r');
Notice::note('one day and one tournament done ', 'bb', 1);
}
}
}
@@ -10,6 +10,7 @@ class CurlSofa
{
public static $testfile = '/Console/Commands/Grapper/Sofascore/test/';
public static function load(string $url)
{
$debug = Nuh::$options['d'] ?? 0;
@@ -9,9 +9,11 @@ use Illuminate\Support\Carbon;
class LoadDays
{
public static function load(int $task_id)
public static function load()
{
$debug = Nuh::$options['d'] ?? 0;
$task_id = Nuh::$options['task'] ?? 0;
$dates = [];
@@ -20,66 +22,63 @@ class LoadDays
return [];
}
$res = SofaScoreTask::with('sport')->where('is_active', 1)->where('id', $task_id)->first();
$task = SofaScoreTask::with('sport')->where('id', $task_id)->first();
if(!$debug){
Notice::note('grapper: '.$res->mode.' sport: '.$res->sport_id);
Notice::note('grapper: '.$task->mode.' sport: '.$task->sport_id);
}
foreach ($res as $row) {
switch ($task->mode) {
switch ($row->mode) {
case 'yesterday':
$dates[] = [
'day' => Carbon::now()->subDay()->format('Y-m-d'),
'slug' => $task->sport->ss_slug,
'run_slow' => $task->run_slow,
'sport_id' => $task->sport_id,
'run_repeatedly' => $task->run_repeatedly,
];
break;
case 'yesterday':
case 'date':
$dates[] = [
'day' => self::validateDate($task->day_from),
'slug' => $task->sport->ss_slug,
'run_slow' => $task->run_slow,
'sport_id' => $task->sport_id,
'run_repeatedly' => $task->run_repeatedly,
];
break;
case 'range':
$from = self::validateDate($task->day_from);
$to = self::validateDate($task->day_to);
$from = Carbon::createFromDate($from);
$to = Carbon::createFromDate($to);
$lengthdates = $from->diffInDays($to);
if ($lengthdates < 1) {
Notice::note('wrong date start must be before end', 'r', 1);
} elseif ($lengthdates > 60) {
Notice::note('wrong date maximal 60 dates allowed', 'r', 1);
}
while ($from <= $to) {
$dates[] = [
'day' => Carbon::now()->subDay()->format('Y-m-d'),
'slug' => $row->sport->ss_slug,
'run_slow' => $row->run_slow,
'sport_id' => $row->sport_id,
'run_repeatedly' => $row->run_repeatedly,
'day' => $from->format('Y-m-d'),
'slug' => $task->sport->ss_slug,
'run_slow' => $task->run_slow,
'sport_id' => $task->sport_id,
'run_repeatedly' => $task->run_repeatedly,
];
break;
$from->addDay();
}
break;
}
case 'date':
$dates[] = [
'day' => self::validateDate($row->day_from),
'slug' => $row->sport->ss_slug,
'run_slow' => $row->run_slow,
'sport_id' => $row->sport_id,
'run_repeatedly' => $row->run_repeatedly,
];
break;
case 'range':
$from = self::validateDate($row->day_from);
$to = self::validateDate($row->day_to);
$from = Carbon::createFromDate($from);
$to = Carbon::createFromDate($to);
$lengthdates = $from->diffInDays($to);
if ($lengthdates < 1) {
Notice::note('wrong date start must be before end', 'r', 1);
} elseif ($lengthdates > 60) {
Notice::note('wrong date maximal 60 dates allowed', 'r', 1);
}
while ($from < $to) {
$dates[] = [
'day' => $from->format('Y-m-d'),
'slug' => $row->sport->ss_slug,
'run_slow' => $row->run_slow,
'sport_id' => $row->sport_id,
'run_repeatedly' => $row->run_repeatedly,
];
$from->addDay();
}
break;
}
if (! $dates) {
Notice::note(__FILE__.PHP_EOL.'no dates', 'r', 1);
}
if (! $dates) {
Notice::note(__FILE__.PHP_EOL.'no dates', 'r', 1);
}
// remove when element in array is double (day and slug)
@@ -2,26 +2,27 @@
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Nuh;
use App\Models\SofaScoreTask;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class TaskConfig
{
public static function set(int $task_id)
public static function start()
{
if(!$task_id){
Notice::note('no task id', 'br');
return [];
}
$task_id = (int) Nuh::$options['task'] ?? 0;
SofaScoreTask::find($task_id)->update(['last_start' => Carbon::now()]);
}
public static function end()
{
$task_id = Nuh::$options['task'] ?? 0;
$res = SofaScoreTask::with('sport')->where('id', $task_id)->first();
if($res->run_repeatedly){
SofaScoreTask::query()->where('id', $task_id)->update(['compleated' => 1]);
SofaScoreTask::query()->where('id', $task_id)->update(['compleated' => 1, 'is_active' => 1, 'last_end' => Carbon::now()]);
}
else {
SofaScoreTask::query()->where('id', $task_id)->update(['compleated' => 1, 'is_active' => 0, 'last_end' => Carbon::now()->format('Y-m-d')]);
SofaScoreTask::query()->where('id', $task_id)->update(['compleated' => 1, 'is_active' => 0, 'last_end' => Carbon::now()]);
}
}
}
@@ -3,13 +3,19 @@
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\Utilities\Notice;
use Illuminate\Support\Facades\Mail;
class SendMail
{
public static function run(array $days)
public static function run()
{
$task = Nuh::$options['task'] ?? 0;
$days = LoadDays::load($task);
foreach ($days as $d) {
$day = $d['day'];
@@ -13,9 +13,9 @@ class SettingsToLocal
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('copy settings to local', 'bb');
Notice::note('Settings To Local', 'bb');
}
SofaScoreTask::truncate();
+3 -3
View File
@@ -23,7 +23,7 @@ class Nuh extends Command
public static $id = 0;
protected $signature = 'nuh {process=help} {--truncate} {--grps=0} {--days=0} {--day=0} {--id=0} {--run=0} {--fn=} {--gid=} {--p} {--d} {--x} {--t} {--y} {--m} {--l} {--w} {--a} {--r} {--s} {--g} {--t} {--q} {--f} {--b} {--e} {--z}';
protected $signature = 'nuh {process=help} {--truncate} {--id=0} {--fun=} {--task=0} {--gid=} {--p} {--d} {--x} {--t} {--y} {--m} {--l} {--w} {--a} {--r} {--s} {--g} {--t} {--q} {--f} {--b} {--e} {--z}';
public function handle()
{
@@ -41,13 +41,13 @@ class Nuh extends Command
$txt .= '-----------------------------------------------------------' . PHP_EOL;
$txt .= 'process [id] (required)' . PHP_EOL;
$txt .= '--id=matchid (optional) calling spezific id' . PHP_EOL;
$txt .= '--fn=name (optional) [bkms, markets]' . PHP_EOL;
$txt .= '--fun=name (optional) [bkms, markets]' . PHP_EOL;
$txt .= '--gid=groupid (optional) [bkms, groupid]' . PHP_EOL;
$txt .= '--truncate (optional)' . PHP_EOL;
$txt .= '-----------------------------------------------------------' . PHP_EOL . PHP_EOL;
$txt .= 'Sofascore (67)' . PHP_EOL;
$txt .= '-----------------------------------------------------------' . PHP_EOL;
$txt .= '--run=[1,2,3,4,5,6,7]'
$txt .= '--fun=[1,2,3,4,5,6,7]'
.PHP_EOL.chr(9).'1) player/season'
.PHP_EOL.chr(9).'2) setting to local'
.PHP_EOL.chr(9).'3) create zip'