This commit is contained in:
salam committed 2026-10-04 10:15:00 +02:00
1 parent fbde80c898
commit 812736ca9a
9 files changed
+203 -189

No files matched your search

+2 -2
View File
@@ -2,12 +2,12 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Traits\Sofascore\GrapSofascore; use App\Traits\Sofascore\GrappingSofascore;
use Illuminate\Console\Command; use Illuminate\Console\Command;
class Grapper extends Command class Grapper extends Command
{ {
use GrapSofascore; use GrappingSofascore;
protected $signature = 'grp:sofa {--d} {--r} {--f}'; protected $signature = 'grp:sofa {--d} {--r} {--f}';
+2 -2
View File
@@ -2,12 +2,12 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Traits\Sofascore\GrapSofascore; use App\Traits\Sofascore\GrappingSofascore;
use Illuminate\Console\Command; use Illuminate\Console\Command;
class GrapperDaily extends Command class GrapperDaily extends Command
{ {
use GrapSofascore; use GrappingSofascore;
protected $signature = 'grp:daily {--d} {--r} {--f}'; protected $signature = 'grp:daily {--d} {--r} {--f}';
+2 -10
View File
@@ -16,18 +16,10 @@ class CloudflareSolverService
* Holt die Daten und gibt das extrahierte JSON als PHP-Array zurück. * Holt die Daten und gibt das extrahierte JSON als PHP-Array zurück.
* Wenn etwas schiefgeht, wird null zurückgegeben. * Wenn etwas schiefgeht, wird null zurückgegeben.
*/ */
public function getJsonFromUrl(string $targetUrl, int $debug): ?array public function getJsonFromUrl(string $targetUrl): ?array
{ {
/** $this->solverUrl = config('services.flaresolverr.id_docker');
* set in .env
* FLARESOLVERR_IP_DOCKER="http://192.168.178.187:8191/v1"
*/
$this->solverUrl = env('FLARESOLVERR_IP_DOCKER', 'http://flaresolverr:8191/v1');
if ($debug) {
Notice::note($this->solverUrl, 'bb');
}
try { try {
$response = Http::withHeaders([ $response = Http::withHeaders([
@@ -10,7 +10,7 @@ use App\Utilities\Notice;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
trait GrapperEvent trait GrappingEvent
{ {
protected function get_event(string $day, array $tournament) protected function get_event(string $day, array $tournament)
{ {
@@ -22,19 +22,17 @@ trait GrapperEvent
Notice::note("$day - " . $tournament['tournament']['name'] . ' - ' . $tournament['sofa_score_tournament_id'], 'bb'); Notice::note("$day - " . $tournament['tournament']['name'] . ' - ' . $tournament['sofa_score_tournament_id'], 'bb');
} }
$this->sleep(1);
$url = $this->base_url . 'api/v1/unique-tournament/' . $tournament['sofa_score_tournament_id'] . "/scheduled-events/$day"; $url = $this->base_url . 'api/v1/unique-tournament/' . $tournament['sofa_score_tournament_id'] . "/scheduled-events/$day";
if ($this->debug) { if ($this->debug) {
Notice::note($url, 'b'); Notice::note($url, 'p');
} }
$this->sleep(2); $this->sleep(1);
$cloudflareService = new CloudflareSolverService; $cloudflareService = new CloudflareSolverService;
$data = $cloudflareService->getJsonFromUrl($url, $this->debug); $data = $cloudflareService->getJsonFromUrl($url);
if (isset($data['events'])) { if (isset($data['events'])) {
@@ -74,7 +72,7 @@ trait GrapperEvent
$this->sleep(); $this->sleep();
$data = $cloudflareService->getJsonFromUrl($url, $this->debug); $data = $cloudflareService->getJsonFromUrl($url);
$data['id'] = $event_id; $data['id'] = $event_id;
@@ -92,7 +90,7 @@ trait GrapperEvent
$this->sleep(); $this->sleep();
$data = $cloudflareService->getJsonFromUrl($url, $this->debug); $data = $cloudflareService->getJsonFromUrl($url);
$data['id'] = $event_id; $data['id'] = $event_id;
@@ -110,7 +108,7 @@ trait GrapperEvent
$this->sleep(); $this->sleep();
$data = $cloudflareService->getJsonFromUrl($url, $this->debug); $data = $cloudflareService->getJsonFromUrl($url);
$data['id'] = $event_id; $data['id'] = $event_id;
@@ -128,7 +126,7 @@ trait GrapperEvent
$this->sleep(); $this->sleep();
$data = $cloudflareService->getJsonFromUrl($url, $this->debug); $data = $cloudflareService->getJsonFromUrl($url);
$data['id'] = $event_id; $data['id'] = $event_id;
@@ -149,6 +147,10 @@ trait GrapperEvent
} }
} }
} }
} else {
if ($this->debug) {
Notice::note($day . ' - ' . $tournament['tournament']['name'] . " no events", 'y');
}
} }
SofaScoreTaskDay::updateOrCreate([ SofaScoreTaskDay::updateOrCreate([
-150
View File
@@ -215,156 +215,6 @@ trait GrappingHelper
} }
} }
/**
* Summary of grap_tournaments_for_day
*
* @return void
*/
protected function grap_tournaments_for_day(string $day)
{
$tournaments_counter = 0;
$sport_id = 1;
$has = SofaScoreDayTournament::where('day', $day)->first();
$slug = 'football';
if (! $this->force && $has) {
if ($this->debug) {
Notice::note("$day tournaments allready grapped", 'br');
}
} else {
if ($this->debug) {
Notice::note("$day tournaments loaded", 'bb');
}
$page = 1;
while ($page) {
// $data = $this->curl($url);
$this->sleep();
$url = $this->base_url . "api/v1/sport/$slug/scheduled-tournaments/$day/page/$page";
$cloudflareService = new CloudflareSolverService;
$data = $cloudflareService->getJsonFromUrl($url, $this->debug);
if ($data['hasNextPage']) {
$page++;
} else {
$page = false;
}
foreach ($data['scheduled'] as $row) {
if (isset($row['tournament']['uniqueTournament'])) {
$tournament = $row['tournament']['uniqueTournament'];
} else {
$tournament = $row['tournament'];
}
$category = $tournament['category'];
if ($sport_id == 5) {
$country_id = 470;
} else {
/**
* CATEGORY
*/
$find = [
'Amateur',
'Bosnia & Herzegovina',
'Czechia',
'DR Congo',
'Netherlands',
'North & Central America',
'Bonaire',
'Sao Tome and Principe',
'Cape Verde',
'Macao',
'Saint Kitts and Nevis',
'Eswatini',
'Timor Leste',
'Laos',
'Congo Republic',
];
$replace = [
'',
'Bosnia Herzegovina',
'Czech Republic',
'Congo DR',
'Holland',
'North America',
'Bonaire, Sint Eustatius and Saba',
'Sao Tome e Principe',
'Cape Verde Islands',
'Macau',
'St. Kitts and Nevis',
'Swaziland',
'East Timor',
'Lao Peoples\'s Democratic Republic',
'Congo DR',
];
$country_id = Country::where('name', trim(str_replace($find, $replace, $category['name'])))->value('id');
}
if (! $country_id) {
// platzhalter fix later sofa_score_categories => txodds countries
// CATEGORY find <-> replace
// Log::channel('sofascore')->info($tournament);
$sofa_score_category_id = 10000000;
} else {
$call = SofaScoreCategory::updateOrCreate([
'id' => (int) $category['id'],
'country_id' => (int) $country_id,
'slug' => $category['slug'],
], [
'name' => $category['name'],
]);
$sofa_score_category_id = $call->id;
}
/**
* TOURNAMENT
*/
SofaScoreTournament::updateOrCreate([
'sport_id' => (int) $sport_id,
'tournament_id' => (int) $tournament['id'],
'sofa_score_category_id' => (int) $sofa_score_category_id,
], [
'name' => $tournament['name'],
'slug' => $tournament['slug'],
]);
$tournaments_counter++;
// if ($debug) {
// Notice::note('tournament: ' . $tournament['name'], 'p');
// }
/**
* DAY TOURNAMENT
*/
SofaScoreDayTournament::updateOrCreate([
'tournament_id' => (int) $tournament['id'],
'sport_id' => (int) $sport_id,
'day' => $day,
]);
}
if ($this->debug) {
Notice::note("tournaments: $tournaments_counter", 'p');
}
}
}
}
protected function get_tree(string $dir, &$results = []) protected function get_tree(string $dir, &$results = [])
{ {
$files = scandir($dir); $files = scandir($dir);
@@ -2,19 +2,22 @@
namespace App\Traits\Sofascore; namespace App\Traits\Sofascore;
use App\Mail\SimpleMail;
use App\Utilities\Notice; use App\Utilities\Notice;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Mail;
use function Laravel\Prompts\select; use function Laravel\Prompts\select;
use function Laravel\Prompts\text; use function Laravel\Prompts\text;
trait GrapSofascore trait GrappingSofascore
{ {
use GrapperEvent; use GrappingEvent;
use GrappingHelper; use GrappingHelper;
use GrappingMail; use GrappingMail;
use GrappingToExcel; use GrappingToExcel;
use GrappingTournaments;
protected int $debug; protected int $debug;
@@ -134,25 +137,25 @@ trait GrapSofascore
* day 1 * day 1
*/ */
$day = Carbon::now()->subDay()->format('Y-m-d'); // $day = Carbon::now()->subDay()->format('Y-m-d');
$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);
} // }
/** /**
* day 5 * day 5
*/ */
$day = Carbon::now()->subDays(5)->format('Y-m-d'); // $day = Carbon::now()->subDays(5)->format('Y-m-d');
$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);
} // }
/** /**
* to excel day by day * to excel day by day
@@ -232,7 +235,7 @@ trait GrapSofascore
if (in_array($day, $day_done)) { if (in_array($day, $day_done)) {
if ($this->debug) { if ($this->debug) {
Notice::note("$day already in folder", 'br'); Notice::note("$day Events allready grapped", 'br');
} }
} else { } else {
$this->grap_tournaments_for_day($day); $this->grap_tournaments_for_day($day);
@@ -246,6 +249,8 @@ trait GrapSofascore
$this->import_to_excel($folder); $this->import_to_excel($folder);
Notice::note('Done', 'g'); Notice::note('Done', 'g');
Mail::to('hermann.telser@gmail.com')->send(new SimpleMail('STATISTIKO', 'Grapping compleated'));
} }
protected function days_done(): array protected function days_done(): array
@@ -0,0 +1,162 @@
<?php
namespace App\Traits\Sofascore;
use App\Models\SofaScoreCategory;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreTournament;
use App\Services\CloudflareSolverService;
use App\Utilities\Notice;
trait GrappingTournaments
{
/**
* Summary of grap_tournaments_for_day
*
* @return void
*/
protected function grap_tournaments_for_day(string $day)
{
$sport_id = 1;
$has = SofaScoreDayTournament::where('day', $day)->first();
$slug = 'football';
if (! $this->force && $has) {
if ($this->debug) {
Notice::note("$day Tournaments allready grapped", 'bb');
}
} else {
$page = 1;
$tournaments_counter = 0;
while ($page) {
// $data = $this->curl($url);
$this->sleep();
$url = $this->base_url . "api/v1/sport/$slug/scheduled-tournaments/$day/page/$page";
$cloudflareService = new CloudflareSolverService;
$data = $cloudflareService->getJsonFromUrl($url);
if ($data['hasNextPage']) {
$page++;
} else {
$page = false;
}
foreach ($data['scheduled'] as $row) {
if (isset($row['tournament']['uniqueTournament'])) {
$tournament = $row['tournament']['uniqueTournament'];
} else {
$tournament = $row['tournament'];
}
$category = $tournament['category'];
if ($sport_id == 5) {
$country_id = 470;
} else {
/**
* CATEGORY
*/
$find = [
'Amateur',
'Bosnia & Herzegovina',
'Czechia',
'DR Congo',
'Netherlands',
'North & Central America',
'Bonaire',
'Sao Tome and Principe',
'Cape Verde',
'Macao',
'Saint Kitts and Nevis',
'Eswatini',
'Timor Leste',
'Laos',
'Congo Republic',
];
$replace = [
'',
'Bosnia Herzegovina',
'Czech Republic',
'Congo DR',
'Holland',
'North America',
'Bonaire, Sint Eustatius and Saba',
'Sao Tome e Principe',
'Cape Verde Islands',
'Macau',
'St. Kitts and Nevis',
'Swaziland',
'East Timor',
'Lao Peoples\'s Democratic Republic',
'Congo DR',
];
$country_id = Country::where('name', trim(str_replace($find, $replace, $category['name'])))->value('id');
}
if (! $country_id) {
// platzhalter fix later sofa_score_categories => txodds countries
// CATEGORY find <-> replace
// Log::channel('sofascore')->info($tournament);
$sofa_score_category_id = 10000000;
} else {
$call = SofaScoreCategory::updateOrCreate([
'id' => (int) $category['id'],
'country_id' => (int) $country_id,
'slug' => $category['slug'],
], [
'name' => $category['name'],
]);
$sofa_score_category_id = $call->id;
}
/**
* TOURNAMENT
*/
SofaScoreTournament::updateOrCreate([
'sport_id' => (int) $sport_id,
'tournament_id' => (int) $tournament['id'],
'sofa_score_category_id' => (int) $sofa_score_category_id,
], [
'name' => $tournament['name'],
'slug' => $tournament['slug'],
]);
$tournaments_counter++;
// if ($debug) {
// Notice::note('tournament: ' . $tournament['name'], 'p');
// }
/**
* DAY TOURNAMENT
*/
SofaScoreDayTournament::updateOrCreate([
'tournament_id' => (int) $tournament['id'],
'sport_id' => (int) $sport_id,
'day' => $day,
]);
}
if ($this->debug) {
Notice::note("Tournaments: $tournaments_counter", 'p');
}
}
if ($this->debug) {
Notice::note("$day Tournaments loaded", 'bb');
}
}
}
}
+4 -1
View File
@@ -14,6 +14,8 @@ return [
| |
*/ */
'postmark' => [ 'postmark' => [
'token' => env('POSTMARK_TOKEN'), 'token' => env('POSTMARK_TOKEN'),
], ],
@@ -36,7 +38,8 @@ return [
], ],
'flaresolverr' => [ 'flaresolverr' => [
'url' => env('FLARESOLVERR_URL', '192.168.178'), 'url' => env('FLARESOLVERR_URL'),
'id_docker' => env('FLARESOLVERR_IP_DOCKER'),
], ],
]; ];
+1 -1
View File
@@ -8,7 +8,7 @@
<body> <body>
<h1>{{ $title }}</h1> <h1>{{ $title }}</h1>
<p>{{ $body }}</p> <p>{{ $body }}</p>
<p>Vielen Dank!</p> <p>All is good!</p>
</body> </body>
</html> </html>