This commit is contained in:
salam committed 2026-09-26 17:49:06 +02:00
1 parent 267b5b9583
commit 911b515021
15 files changed
+1048 -56

No files matched your search

+57 -25
View File
@@ -5,7 +5,6 @@ namespace App\Console\Commands;
use App\Console\Commands\Grapper\Sofascore\Grapper;
use App\Console\Commands\Grapper\Sofascore\GrapperTest;
use App\Console\Commands\Grapper\Sofascore\Helper\ClearDir;
use App\Console\Commands\Grapper\Sofascore\Helper\RemoveDir;
use App\Console\Commands\Grapper\Sofascore\Helper\SetStorage;
use App\Console\Commands\Grapper\Sofascore\MakeExcel;
use App\Console\Commands\Grapper\Sofascore\Rose;
@@ -29,7 +28,7 @@ class Grap extends Command
public static string $useragent = '4';
protected $signature = 'grp {id=0} {day=0} {--date=} {--folder=} {--d} {--g} {--r} {--c} {--m} {--f} {--F} {--R} {--S}';
protected $signature = 'grp {id=0} {mode} {day=0} {--date=} {--folder=} {--d} {--g} {--r} {--c} {--m} {--f} {--F} {--R} {--S}';
public function handle()
{
@@ -39,38 +38,71 @@ class Grap extends Command
self::$options['base_url'] = 'https://www.sofascore.com/';
if (! self::$options['id']) {
$txt = 'PARAMETERS' . PHP_EOL;
$txt .= '--d debug' . PHP_EOL;
$txt .= '--r restart range' . PHP_EOL;
$txt .= '--f force Events' . PHP_EOL;
$txt .= '--F force DayTournament links' . PHP_EOL;
$txt .= '--c clear grap dir' . PHP_EOL;
$txt .= '--m mail only' . PHP_EOL;
$txt .= '--C clear folder' . PHP_EOL;
$txt .= '--G grap' . PHP_EOL;
$txt .= '--E make excel' . PHP_EOL;
$txt .= '--M mail' . PHP_EOL;
$txt .= '--folder' . PHP_EOL;
$txt .= '-----------------------------------------------------------' . PHP_EOL;
$txt .= 'FUNCTION' . PHP_EOL;
$txt .= ' 1 grapper DAILY & subDays ( default 3)' . PHP_EOL;
$txt .= ' 2 grapper MORE DAYS' . PHP_EOL;
$txt .= ' 3 grapper RANGE' . PHP_EOL;
$txt .= ' 4 grapper ROSE' . PHP_EOL;
$txt .= ' 5 import to excel from folder' . PHP_EOL;
$txt .= ' 7 settings to local' . PHP_EOL;
$txt .= ' 11 move SQL' . PHP_EOL;
$txt .= ' 12 testing url for grapping' . PHP_EOL;
$txt = 'PARAMETERS'.PHP_EOL;
$txt .= '--d debug'.PHP_EOL;
$txt .= '--r restart range'.PHP_EOL;
$txt .= '--f force Events'.PHP_EOL;
$txt .= '--F force DayTournament links'.PHP_EOL;
$txt .= '--c clear grap dir'.PHP_EOL;
$txt .= '--m mail only'.PHP_EOL;
$txt .= '--C clear folder'.PHP_EOL;
$txt .= '--G grap'.PHP_EOL;
$txt .= '--E make excel'.PHP_EOL;
$txt .= '--M mail'.PHP_EOL;
$txt .= '--folder'.PHP_EOL;
$txt .= '-----------------------------------------------------------'.PHP_EOL;
$txt .= 'FUNCTION'.PHP_EOL;
$txt .= ' 1 grapper DAILY & subDays ( default 3)'.PHP_EOL;
$txt .= ' 2 grapper MORE DAYS'.PHP_EOL;
$txt .= ' 3 grapper RANGE'.PHP_EOL;
$txt .= ' 4 grapper ROSE'.PHP_EOL;
$txt .= ' 5 import to excel from folder'.PHP_EOL;
$txt .= ' 7 settings to local'.PHP_EOL;
$txt .= ' 11 move SQL'.PHP_EOL;
$txt .= ' 12 testing url for grapping'.PHP_EOL;
Notice::note($txt, 'b', 1);
}
Notice::note('Task Id ' . self::$options['id'], 'gb');
Notice::note('Task Id '.self::$options['id'], 'gb');
if (self::$options['cear']) {
SetStorage::set(1);
ClearDir::clear();
}
if (self::$options['grap']) {
SetStorage::set(1);
Grapper::load(1);
}
if (self::$options['excel']) {
SetStorage::set(1);
MakeExcel::create();
}
if (self::$options['mail']) {
SetStorage::set(1);
SendMail::run(1);
}
case 4:
// ROSE
SetStorage::set(4);
Rose::run();
MakeExcel::create();
break;
switch (self::$options['id']) {
case 1:
// DAILY
if (self::$options['c']) {
SetStorage::set(1);
ClearDir::clear();
}
if (self::$options['C']) {
Grapper::load(1);
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Console\Commands;
use App\Traits\GrapSofascore;
use Illuminate\Console\Command;
class Grapper extends Command
{
use GrapSofascore;
protected $signature = 'grp:sofa {--d} {--r} {--f}';
protected $description = 'grap sofascore';
public function handleUpdate(string $grapperSelected): void
{
$this->runGrapper($grapperSelected);
}
}
@@ -47,9 +47,8 @@ class Grapper
break;
}
/**
* Restart
* Restart
*/
if ($restart) {
@@ -83,21 +82,21 @@ class Grapper
Notice::note($tournament->sofa_score_tournament_id, 'bb');
}
if (! $force)
if (! $force) {
Sleeper::rand(1);
else
} else {
Sleeper::rand();
}
if ($debug) {
Notice::note($day, 'br');
}
$url = Grap::$options['base_url'] . "api/v1/unique-tournament/$tournament->sofa_score_tournament_id/scheduled-events/$day";
$url = Grap::$options['base_url']."api/v1/unique-tournament/$tournament->sofa_score_tournament_id/scheduled-events/$day";
$data = CurlSofa::load($url);
Notice::note($data, 'bb');
if (isset($data['events'])) {
if ($debug) {
@@ -110,7 +109,7 @@ class Grapper
if (! $force && SofaScoreEventGrapped::where('grapper_id', $task_id)->where('id', (int) $event['id'])->exists()) {
if ($debug) {
Notice::note('DB - Allready grapped at ' . $day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'g');
Notice::note('DB - Allready grapped at '.$day.' - '.$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'g');
}
} else {
@@ -124,17 +123,17 @@ class Grapper
// if ($now->greaterThan($starttime) && $starttime->isSameDay($carbon_day)) {
if (! $force)
if (! $force) {
Sleeper::rand(1);
else
} else {
Sleeper::rand();
if ($debug) {
Notice::note($day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'bg');
}
$folder = strtolower(Grap::$storage . '/' . $day . '/' . $day . '-' . $event['tournament']['category']['slug'] . '-' . $event['tournament']['slug'] . '/' . $event['slug']);
if ($debug) {
Notice::note($day.' - '.$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'bg');
}
$folder = strtolower(Grap::$storage.'/'.$day.'/'.$day.'-'.$event['tournament']['category']['slug'].'-'.$event['tournament']['slug'].'/'.$event['slug']);
File::makeDirectory($folder, 0775, true, true);
@@ -142,7 +141,7 @@ class Grapper
* EVENT event
*********************************/
File::put($folder . '/event.json', json_encode($event));
File::put($folder.'/event.json', json_encode($event));
/*********************************
* EVENT statistics
@@ -150,7 +149,7 @@ class Grapper
$event_id = $event['id'];
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/statistics";
$url = Grap::$options['base_url']."api/v1/event/$event_id/statistics";
Sleeper::rand();
@@ -158,13 +157,13 @@ class Grapper
$data['id'] = $event_id;
File::put($folder . '/statistics.json', json_encode($data));
File::put($folder.'/statistics.json', json_encode($data));
/*********************************
* EVENT lineups
*********************************/
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/lineups";
$url = Grap::$options['base_url']."api/v1/event/$event_id/lineups";
Sleeper::rand();
@@ -172,13 +171,13 @@ class Grapper
$data['id'] = $event_id;
File::put($folder . '/lineups.json', json_encode($data));
File::put($folder.'/lineups.json', json_encode($data));
/*********************************
* EVENT odds
*********************************/
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/odds/1/all";
$url = Grap::$options['base_url']."api/v1/event/$event_id/odds/1/all";
Sleeper::rand();
@@ -186,13 +185,13 @@ class Grapper
$data['id'] = $event_id;
File::put($folder . '/odds.json', json_encode($data));
File::put($folder.'/odds.json', json_encode($data));
/*********************************
* EVENT incidents
*********************************/
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/incidents";
$url = Grap::$options['base_url']."api/v1/event/$event_id/incidents";
Sleeper::rand();
@@ -200,13 +199,13 @@ class Grapper
$data['id'] = $event_id;
File::put($folder . '/incidents.json', json_encode($data));
File::put($folder.'/incidents.json', json_encode($data));
$grapped = SofaScoreEventGrapped::firstOrNew(['id' => $event['id']]);
$grapped->grapper_id = $task_id;
$grapped->day = $day;
$grapped->liga = $event['tournament']['name'];
$grapped->name = $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'];
$grapped->name = $event['homeTeam']['name'].' vs '.$event['awayTeam']['name'];
$grapped->url = $url;
$grapped->starttime = $starttime->toDateTimeString();
$grapped->save();
@@ -230,10 +229,11 @@ class Grapper
Notice::note("$count days done, sleep 10-20 sec", 'p');
}
if (! $force)
if (! $force) {
Sleeper::rand(2);
else
} else {
Sleeper::rand();
}
}
}
}
@@ -5,7 +5,6 @@ namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Grap;
use App\Utilities\Notice;
class CurlSofa
{
public static function load(string $url)
@@ -49,7 +48,7 @@ class CurlSofa
// Cache-Control: no-cache
// TE: trailers
$headers = [
'User-Agent: ' . $useragents[Grap::$useragent],
'User-Agent: '.$useragents[Grap::$useragent],
'Accept: */*',
'Accept-Language: de,en-US;q=0.7,en;q=0.3',
'Accept-Encoding: gzip, deflate, br, zstd',
@@ -64,7 +63,7 @@ class CurlSofa
'Priority: u=4',
'Pragma: no-cache',
'Cache-Control: no-cache',
'TE: trailers'
'TE: trailers',
];
$ch = curl_init();
-1
View File
@@ -1 +0,0 @@
Commands/Grapper/Sofascore