centralized grapper tournaments wi

This commit is contained in:
salam committed 2026-10-11 15:42:00 +02:00
1 parent 34701ecbff
commit db917bdc92
7 files changed
+236 -30

No files matched your search

+4
View File
@@ -6,6 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class SofaScoreDayTournament extends Model class SofaScoreDayTournament extends Model
{ {
protected $connection = 'mariadb';
protected $table = 'sofa_score_day_tournaments';
protected $fillable = [ protected $fillable = [
'id', 'id',
'tournament_id', 'tournament_id',
+2
View File
@@ -11,6 +11,8 @@ class SofaScoreEventGrapped extends Model
'grapper_id', 'grapper_id',
'name', 'name',
'url', 'url',
'day',
'liga',
'starttime', 'starttime',
'got_statistics', 'got_statistics',
'got_lineups', 'got_lineups',
+52 -14
View File
@@ -2,9 +2,7 @@
namespace App\Traits\Sofascore; namespace App\Traits\Sofascore;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreEventGrapped; use App\Models\SofaScoreEventGrapped;
use App\Models\SofaScoreTaskDay;
use App\Services\CloudflareSolverService; use App\Services\CloudflareSolverService;
use App\Utilities\Notice; use App\Utilities\Notice;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
@@ -14,9 +12,9 @@ trait GrappingEvent
{ {
protected function get_event(string $day, array $tournament) protected function get_event(string $day, array $tournament)
{ {
$res = SofaScoreDayTournament::whereDate('day', '=', $day)->where('tournament_id', $tournament['sofa_score_tournament_id'])->first(); foreach ($this->day_tournaments as $day_tournament) {
if ($res) { if ($day_tournament->tournament_id == $tournament['sofa_score_tournament_id']) {
if ($this->debug) { if ($this->debug) {
Notice::note("$day - ".$tournament['tournament']['name'].' - '.$tournament['sofa_score_tournament_id'], 'bb'); Notice::note("$day - ".$tournament['tournament']['name'].' - '.$tournament['sofa_score_tournament_id'], 'bb');
@@ -38,6 +36,16 @@ trait GrappingEvent
foreach ($data['events'] as $event) { foreach ($data['events'] as $event) {
$base_check_string = $day.'-'.$event['tournament']['category']['slug'].'-'.$event['tournament']['slug'].'/'.$event['slug'];
$res = SofaScoreEventGrapped::where('id', (int) $event['id'])->where('grapper_id', $this->task_id)->first();
if (! $res) {
$base_check_string = $day.'-'.$event['tournament']['category']['slug'].'-'.$event['tournament']['slug'].'/'.$event['slug'];
// chinese-super-league
if (! $this->restart && SofaScoreEventGrapped::where('grapper_id', $this->task_id)->where('id', (int) $event['id'])->exists()) { if (! $this->restart && SofaScoreEventGrapped::where('grapper_id', $this->task_id)->where('id', (int) $event['id'])->exists()) {
if ($this->debug) { if ($this->debug) {
Notice::note('DB - Allready grapped at '.$day.' - '.$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'b'); Notice::note('DB - Allready grapped at '.$day.' - '.$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'b');
@@ -64,6 +72,8 @@ trait GrappingEvent
$event_id = $event['id']; $event_id = $event['id'];
if (! $this->grapped($base_check_string.'/statistics.json')) {
$url = $this->base_url."api/v1/event/$event_id/statistics"; $url = $this->base_url."api/v1/event/$event_id/statistics";
if ($this->debug) { if ($this->debug) {
@@ -78,10 +88,18 @@ trait GrappingEvent
File::put("$folder/statistics.json", json_encode($data)); File::put("$folder/statistics.json", json_encode($data));
} else {
if ($this->debug) {
Notice::note('already grapped statistics.json', 'y');
}
}
/********************************* /*********************************
* EVENT lineups * EVENT lineups
*********************************/ *********************************/
if (! $this->grapped($base_check_string.'/lineups.json')) {
$url = $this->base_url."api/v1/event/$event_id/lineups"; $url = $this->base_url."api/v1/event/$event_id/lineups";
if ($this->debug) { if ($this->debug) {
@@ -96,10 +114,18 @@ trait GrappingEvent
File::put("$folder/lineups.json", json_encode($data)); File::put("$folder/lineups.json", json_encode($data));
} else {
if ($this->debug) {
Notice::note('already grapped lineups.json', 'y');
}
}
/********************************* /*********************************
* EVENT odds * EVENT odds
*********************************/ *********************************/
if (! $this->grapped($base_check_string.'/odds.json')) {
$url = $this->base_url."api/v1/event/$event_id/odds/1/all"; $url = $this->base_url."api/v1/event/$event_id/odds/1/all";
if ($this->debug) { if ($this->debug) {
@@ -113,11 +139,17 @@ trait GrappingEvent
$data['id'] = $event_id; $data['id'] = $event_id;
File::put("$folder/odds.json", json_encode($data)); File::put("$folder/odds.json", json_encode($data));
} else {
if ($this->debug) {
Notice::note('already grapped odds.json', 'y');
}
}
/********************************* /*********************************
* EVENT incidents * EVENT incidents
*********************************/ *********************************/
if (! $this->grapped($base_check_string.'/incidents.json')) {
$url = $this->base_url."api/v1/event/$event_id/incidents"; $url = $this->base_url."api/v1/event/$event_id/incidents";
if ($this->debug) { if ($this->debug) {
@@ -132,6 +164,12 @@ trait GrappingEvent
File::put("$folder/incidents.json", json_encode($data)); File::put("$folder/incidents.json", json_encode($data));
} else {
if ($this->debug) {
Notice::note('already grapped incidents.json', 'y');
}
}
$starttime = Carbon::createFromTimestamp($event['startTimestamp']); $starttime = Carbon::createFromTimestamp($event['startTimestamp']);
SofaScoreEventGrapped::updateOrCreate([ SofaScoreEventGrapped::updateOrCreate([
@@ -145,19 +183,19 @@ trait GrappingEvent
'starttime' => $starttime->toDateTimeString(), 'starttime' => $starttime->toDateTimeString(),
]); ]);
} }
}
}
} else { } else {
if ($this->debug) { if ($this->debug) {
Notice::note($day . ' - ' . $tournament['tournament']['name'] . " no events", 'y'); Notice::note('grapped: '.$base_check_string, 'p');
}
}
} }
} }
SofaScoreTaskDay::updateOrCreate([ return;
'grapper_id' => (int) $this->task_id, }
'day' => $day, }
], [ if ($this->debug) {
'done' => 1, Notice::note($day.' - '.$tournament['tournament']['name'].' no events', 'y');
]); }
} }
} }
+19 -5
View File
@@ -2,17 +2,12 @@
namespace App\Traits\Sofascore; namespace App\Traits\Sofascore;
use App\Models\Country;
use App\Models\SofaScoreCategory;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreEventGrapped;
use App\Models\SofaScoreRosa; use App\Models\SofaScoreRosa;
use App\Models\SofaScoreTask; use App\Models\SofaScoreTask;
use App\Models\SofaScoreTaskDay; use App\Models\SofaScoreTaskDay;
use App\Models\SofaScoreTaskTournament; use App\Models\SofaScoreTaskTournament;
use App\Models\SofaScoreTournament; use App\Models\SofaScoreTournament;
use App\Models\StatistikoImport; use App\Models\StatistikoImport;
use App\Services\CloudflareSolverService;
use App\Utilities\Notice; use App\Utilities\Notice;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@@ -125,6 +120,12 @@ trait GrappingHelper
*/ */
protected function load_tournaments_requested(string $grapperSelected) protected function load_tournaments_requested(string $grapperSelected)
{ {
/**
* SofaScoreDayTournament
*/
if ($this->debug) {
Notice::note('get tournaments for grapper', 'g');
}
switch ($grapperSelected) { switch ($grapperSelected) {
case 'daily': case 'daily':
$this->tournaments_requested = SofaScoreTaskTournament::with('tournament')->where('sofa_score_task_id', 1)->where('disabled', false)->get()->toArray(); $this->tournaments_requested = SofaScoreTaskTournament::with('tournament')->where('sofa_score_task_id', 1)->where('disabled', false)->get()->toArray();
@@ -217,6 +218,7 @@ trait GrappingHelper
protected function get_tree(string $dir, &$results = []) protected function get_tree(string $dir, &$results = [])
{ {
if (File::isDirectory($dir)) {
$files = scandir($dir); $files = scandir($dir);
foreach ($files as $value) { foreach ($files as $value) {
$path = realpath($dir.DIRECTORY_SEPARATOR.$value); $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
@@ -227,10 +229,22 @@ trait GrappingHelper
$results[] = $path; $results[] = $path;
} }
} }
}
return $results; return $results;
} }
protected function grapped(string $string)
{
foreach ($this->grapped_files as $file) {
if (strpos($file, $string) !== false) {
return true;
}
}
return false;
}
protected function clean_string(string $string) protected function clean_string(string $string)
{ {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
+33 -8
View File
@@ -3,8 +3,11 @@
namespace App\Traits\Sofascore; namespace App\Traits\Sofascore;
use App\Mail\SimpleMail; use App\Mail\SimpleMail;
use App\Models\SofaScoreEventGrapped;
use App\Models\SofaScoreTaskDay;
use App\Utilities\Notice; use App\Utilities\Notice;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
@@ -37,6 +40,10 @@ trait GrappingSofascore
protected array $tournaments_requested = []; protected array $tournaments_requested = [];
protected array $grapped_files = [];
protected Collection $day_tournaments;
protected array $days = []; protected array $days = [];
public function handle(): void public function handle(): void
@@ -116,8 +123,6 @@ trait GrappingSofascore
$this->task_id = 1; $this->task_id = 1;
$this->restart = 1;
$this->set_base_dir($folder); $this->set_base_dir($folder);
$this->load_tournaments_requested($folder); $this->load_tournaments_requested($folder);
@@ -126,9 +131,14 @@ trait GrappingSofascore
switch ($restart) { switch ($restart) {
case 'restart': case 'restart':
$this->restart = 1; $this->restart = 1;
SofaScoreEventGrapped::truncate();
break; break;
case 'clear': case 'clear':
$this->restart = 1; $this->restart = 1;
SofaScoreEventGrapped::truncate();
$this->clear_folder($folder, 'all'); $this->clear_folder($folder, 'all');
break; break;
} }
@@ -136,37 +146,47 @@ trait GrappingSofascore
/** /**
* day 1 * day 1
*/ */
$day = Carbon::now()->subDay()->format('Y-m-d'); $day = Carbon::now()->subDay()->format('Y-m-d');
$res = SofaScoreTaskDay::where('grapper_id', (int) $this->task_id)->where('day', $day)->first();
if (! $res) {
$this->grapped_files = $this->get_tree($this->data_dir.'/'.$day);
$this->grap_tournaments_for_day($day); $this->grap_tournaments_for_day($day);
foreach ($this->tournaments_requested as $tournament) { foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament); $this->get_event($day, $tournament);
} }
SofaScoreTaskDay::updateOrCreate(['grapper_id' => (int) $this->task_id, 'day' => $day], ['done' => 1]);
}
/** /**
* day 5 * day 5
*/ */
$day = Carbon::now()->subDays(5)->format('Y-m-d'); $day = Carbon::now()->subDays(5)->format('Y-m-d');
$res = SofaScoreTaskDay::where('grapper_id', (int) $this->task_id)->where('day', $day)->first();
if (! $res) {
$this->grapped_files = $this->get_tree($this->data_dir.'/'.$day);
$this->grap_tournaments_for_day($day); $this->grap_tournaments_for_day($day);
foreach ($this->tournaments_requested as $tournament) { foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament); $this->get_event($day, $tournament);
} }
SofaScoreTaskDay::updateOrCreate(['grapper_id' => (int) $this->task_id, 'day' => $day], ['done' => 1]);
}
/** /**
* to excel day by day * to excel day by day
*/ */
$this->import_to_excel($folder); $this->import_to_excel($folder);
/** /**
* mail it * mail it
*/ */
$this->send($folder); $this->send($folder);
} }
@@ -188,6 +208,8 @@ trait GrappingSofascore
foreach ($this->tournaments_requested as $tournament) { foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament); $this->get_event($day, $tournament);
} }
SofaScoreTaskDay::updateOrCreate(['grapper_id' => (int) $this->task_id, 'day' => $day], ['done' => 1]);
} }
if ($this->debug) { if ($this->debug) {
@@ -243,6 +265,8 @@ trait GrappingSofascore
foreach ($this->tournaments_requested as $tournament) { foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament); $this->get_event($day, $tournament);
} }
SofaScoreTaskDay::updateOrCreate(['grapper_id' => (int) $this->task_id, 'day' => $day], ['done' => 1]);
} }
} }
@@ -258,8 +282,9 @@ trait GrappingSofascore
$directories = File::directories($this->data_dir); $directories = File::directories($this->data_dir);
$arr = []; $arr = [];
foreach ($directories as $directory) { foreach ($directories as $directory) {
$arr[] = substr(strrchr($directory, "/"), 1); $arr[] = substr(strrchr($directory, '/'), 1);
} }
return $arr; return $arr;
} }
+42 -3
View File
@@ -20,22 +20,49 @@ trait GrappingTournaments
{ {
$sport_id = 1; $sport_id = 1;
$has = SofaScoreDayTournament::where('day', $day)->first(); if ($this->debug) {
Notice::note('⚽ tournaments for day '.$day);
Notice::note('⚽ close all vpn');
}
exec('killall ssh');
$slug = 'football'; if ($this->debug) {
Notice::note('⚽ open vpn');
}
exec('ssh -f -N -L 13306:127.0.0.1:3306 -p 58371 root@162.55.242.190');
/**
* SofaScoreDayTournament
*/
if ($this->debug) {
Notice::note('get tournaments', 'g');
}
if (! $this->force && $has) { $this->day_tournaments = SofaScoreDayTournament::where('day', $day)->get();
if (! $this->restart && $this->day_tournaments->count() > 0) {
if ($this->debug) { if ($this->debug) {
Notice::note("$day Tournaments allready grapped", 'bb'); Notice::note("$day Tournaments allready grapped", 'bb');
} }
if ($this->debug) {
Notice::note('⚽ close all vpn');
}
exec('killall ssh');
return;
} else { } else {
$page = 1; $page = 1;
$tournaments_counter = 0; $tournaments_counter = 0;
$slug = 'football';
while ($page) { while ($page) {
// $data = $this->curl($url); // $data = $this->curl($url);
if ($this->debug) {
Notice::note('⚽ close all vpn and load tournaments');
}
$this->sleep(); $this->sleep();
$url = $this->base_url."api/v1/sport/$slug/scheduled-tournaments/$day/page/$page"; $url = $this->base_url."api/v1/sport/$slug/scheduled-tournaments/$day/page/$page";
@@ -158,6 +185,18 @@ trait GrappingTournaments
if ($this->debug) { if ($this->debug) {
Notice::note("$day Tournaments loaded", 'bb'); Notice::note("$day Tournaments loaded", 'bb');
} }
if ($this->debug) {
Notice::note('⚽ close all vpn');
}
$this->day_tournaments = SofaScoreDayTournament::where('day', $day)->get();
if ($this->debug) {
Notice::note('⚽ close all vpn');
}
exec('killall ssh');
} }
} }
} }
+84
View File
@@ -0,0 +1,84 @@
APP_NAME=Odds
APP_ENV=local
APP_KEY=base64:xhigDJOEk2dBUc3pfYXm7yo8a14PTtVCIU4PAt+F2dM=
APP_DEBUG=1
APP_URL=https://nuhodds_fi4.test
# BETSAPI_TOKEN="36152-aeTRNnZxSPUwGe"
# TXODDS_TOKEN_SOCCER="ident=betaid1&passwd=Dy59vpRC"
# TXODDS_TOKEN_OTHER="ident=betaid2&passwd=Dy59vpRC"
# LOGIFUTURE_TOKEN="uSwIqs!Y3eHrNbyH"
# Da Laravel lokal (via Brew) läuft, greift es über localhost auf Docker zu
FLARESOLVERR_URL=http://192.168.145
FLARESOLVERR_IP_DOCKER=http://localhost:8191/v1
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database
PHP_CLI_SERVER_WORKERS=4
BCRYPT_ROUNDS=12
LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
APP_TIMEZONE=Europe/Vienna
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=nuhodds_fi4
DB_USERNAME=root
DB_PASSWORD=salam
DB_REMOTE_HOST=162.55.242.190
DB_REMOTE_PORT=3306
DB_REMOTE_DATABASE=day_tournament
DB_REMOTE_USERNAME=root
DB_REMOTE_PASSWORD=salam
MONGODB_URI="mongodb://localhost:27017/"
MONGO_DATABASE=nuhodds
SESSION_DRIVER=file
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
CACHE_STORE=database
# CACHE_PREFIX=
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mail.your-server.de
MAIL_PORT=587
MAIL_USERNAME=hermann.telser@nuhodds.com
MAIL_PASSWORD=6j7c3RI9moCPt33h
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hermann.telser@nuhodds.com
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"