wip
This commit is contained in:
1 parent
fbde80c898
commit
812736ca9a
9 files changed
+203
-189
No files matched your search
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Traits\Sofascore\GrapSofascore;
|
||||
use App\Traits\Sofascore\GrappingSofascore;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class Grapper extends Command
|
||||
{
|
||||
use GrapSofascore;
|
||||
use GrappingSofascore;
|
||||
|
||||
protected $signature = 'grp:sofa {--d} {--r} {--f}';
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Traits\Sofascore\GrapSofascore;
|
||||
use App\Traits\Sofascore\GrappingSofascore;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class GrapperDaily extends Command
|
||||
{
|
||||
use GrapSofascore;
|
||||
use GrappingSofascore;
|
||||
|
||||
protected $signature = 'grp:daily {--d} {--r} {--f}';
|
||||
|
||||
|
||||
@@ -16,18 +16,10 @@ class CloudflareSolverService
|
||||
* Holt die Daten und gibt das extrahierte JSON als PHP-Array zurück.
|
||||
* Wenn etwas schiefgeht, wird null zurückgegeben.
|
||||
*/
|
||||
public function getJsonFromUrl(string $targetUrl, int $debug): ?array
|
||||
public function getJsonFromUrl(string $targetUrl): ?array
|
||||
{
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
$this->solverUrl = config('services.flaresolverr.id_docker');
|
||||
|
||||
try {
|
||||
$response = Http::withHeaders([
|
||||
|
||||
@@ -10,7 +10,7 @@ use App\Utilities\Notice;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
trait GrapperEvent
|
||||
trait GrappingEvent
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
$this->sleep(1);
|
||||
|
||||
$url = $this->base_url . 'api/v1/unique-tournament/' . $tournament['sofa_score_tournament_id'] . "/scheduled-events/$day";
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note($url, 'b');
|
||||
Notice::note($url, 'p');
|
||||
}
|
||||
|
||||
$this->sleep(2);
|
||||
$this->sleep(1);
|
||||
|
||||
$cloudflareService = new CloudflareSolverService;
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url, $this->debug);
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
if (isset($data['events'])) {
|
||||
|
||||
@@ -74,7 +72,7 @@ trait GrapperEvent
|
||||
|
||||
$this->sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url, $this->debug);
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
@@ -92,7 +90,7 @@ trait GrapperEvent
|
||||
|
||||
$this->sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url, $this->debug);
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
@@ -110,7 +108,7 @@ trait GrapperEvent
|
||||
|
||||
$this->sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url, $this->debug);
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
@@ -128,7 +126,7 @@ trait GrapperEvent
|
||||
|
||||
$this->sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url, $this->debug);
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$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([
|
||||
@@ -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 = [])
|
||||
{
|
||||
$files = scandir($dir);
|
||||
|
||||
+18
-13
@@ -2,19 +2,22 @@
|
||||
|
||||
namespace App\Traits\Sofascore;
|
||||
|
||||
use App\Mail\SimpleMail;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
use function Laravel\Prompts\select;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
trait GrapSofascore
|
||||
trait GrappingSofascore
|
||||
{
|
||||
use GrapperEvent;
|
||||
use GrappingEvent;
|
||||
use GrappingHelper;
|
||||
use GrappingMail;
|
||||
use GrappingToExcel;
|
||||
use GrappingTournaments;
|
||||
|
||||
protected int $debug;
|
||||
|
||||
@@ -134,25 +137,25 @@ trait GrapSofascore
|
||||
* 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) {
|
||||
$this->get_event($day, $tournament);
|
||||
}
|
||||
// foreach ($this->tournaments_requested as $tournament) {
|
||||
// $this->get_event($day, $tournament);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$this->get_event($day, $tournament);
|
||||
}
|
||||
// foreach ($this->tournaments_requested as $tournament) {
|
||||
// $this->get_event($day, $tournament);
|
||||
// }
|
||||
|
||||
/**
|
||||
* to excel day by day
|
||||
@@ -232,7 +235,7 @@ trait GrapSofascore
|
||||
|
||||
if (in_array($day, $day_done)) {
|
||||
if ($this->debug) {
|
||||
Notice::note("$day already in folder", 'br');
|
||||
Notice::note("$day Events allready grapped", 'br');
|
||||
}
|
||||
} else {
|
||||
$this->grap_tournaments_for_day($day);
|
||||
@@ -246,6 +249,8 @@ trait GrapSofascore
|
||||
$this->import_to_excel($folder);
|
||||
|
||||
Notice::note('Done', 'g');
|
||||
|
||||
Mail::to('hermann.telser@gmail.com')->send(new SimpleMail('STATISTIKO', 'Grapping compleated'));
|
||||
}
|
||||
|
||||
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
@@ -14,6 +14,8 @@ return [
|
||||
|
|
||||
*/
|
||||
|
||||
|
||||
|
||||
'postmark' => [
|
||||
'token' => env('POSTMARK_TOKEN'),
|
||||
],
|
||||
@@ -36,7 +38,8 @@ return [
|
||||
],
|
||||
|
||||
'flaresolverr' => [
|
||||
'url' => env('FLARESOLVERR_URL', '192.168.178'),
|
||||
'url' => env('FLARESOLVERR_URL'),
|
||||
'id_docker' => env('FLARESOLVERR_IP_DOCKER'),
|
||||
],
|
||||
|
||||
];
|
||||
@@ -8,7 +8,7 @@
|
||||
<body>
|
||||
<h1>{{ $title }}</h1>
|
||||
<p>{{ $body }}</p>
|
||||
<p>Vielen Dank!</p>
|
||||
<p>All is good!</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in new issue
Block a user