siplify grapper ask for speed
This commit is contained in:
1 parent
8ec2203918
commit
d221ff6eac
36 files changed
+111
-18439
No files matched your search
@@ -7,7 +7,7 @@ trait CurlSofa
|
||||
protected function curl(string $url)
|
||||
{
|
||||
$headers = [
|
||||
'User-Agent: '.$this->useragent(),
|
||||
'User-Agent: ' . $this->useragent(),
|
||||
'Accept: */*',
|
||||
'Accept-Language: de,en-US;q=0.7,en;q=0.8',
|
||||
'Accept-Encoding: gzip, deflate, br, zstd',
|
||||
@@ -38,7 +38,6 @@ trait CurlSofa
|
||||
$data = json_decode($data, true);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
protected function useragent()
|
||||
@@ -60,7 +59,7 @@ trait CurlSofa
|
||||
return $array[array_rand($array)];
|
||||
}
|
||||
|
||||
protected function sleep($speed = false)
|
||||
protected function grapper_sleep($speed = false)
|
||||
{
|
||||
switch ($speed) {
|
||||
case 1:
|
||||
|
||||
@@ -17,16 +17,16 @@ trait GrappingEvent
|
||||
if ($day_tournament->tournament_id == $tournament['sofa_score_tournament_id']) {
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
$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) {
|
||||
Notice::note($url, 'p');
|
||||
}
|
||||
|
||||
$this->sleep(1);
|
||||
$this->grapper_sleep($this->speed);
|
||||
|
||||
$cloudflareService = new CloudflareSolverService;
|
||||
|
||||
@@ -36,27 +36,27 @@ trait GrappingEvent
|
||||
|
||||
foreach ($data['events'] as $event) {
|
||||
|
||||
$base_check_string = $day.'-'.$event['tournament']['category']['slug'].'-'.$event['tournament']['slug'].'/'.$event['slug'];
|
||||
$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'];
|
||||
$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->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');
|
||||
}
|
||||
} else {
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note("$day - ".$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'g');
|
||||
Notice::note("$day - " . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'g');
|
||||
}
|
||||
|
||||
$folder = strtolower("$this->data_dir/$day/$day-".$event['tournament']['category']['slug'].'-'.$event['tournament']['slug'].'/'.$event['slug']);
|
||||
$folder = strtolower("$this->data_dir/$day/$day-" . $event['tournament']['category']['slug'] . '-' . $event['tournament']['slug'] . '/' . $event['slug']);
|
||||
|
||||
File::makeDirectory($folder, 0775, true, true);
|
||||
|
||||
@@ -72,22 +72,21 @@ trait GrappingEvent
|
||||
|
||||
$event_id = $event['id'];
|
||||
|
||||
if (! $this->grapped($base_check_string.'/statistics.json')) {
|
||||
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) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$this->sleep();
|
||||
$this->grapper_sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put("$folder/statistics.json", json_encode($data));
|
||||
|
||||
} else {
|
||||
if ($this->debug) {
|
||||
Notice::note('already grapped statistics.json', 'y');
|
||||
@@ -98,22 +97,21 @@ trait GrappingEvent
|
||||
* EVENT lineups
|
||||
*********************************/
|
||||
|
||||
if (! $this->grapped($base_check_string.'/lineups.json')) {
|
||||
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) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$this->sleep();
|
||||
$this->grapper_sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put("$folder/lineups.json", json_encode($data));
|
||||
|
||||
} else {
|
||||
if ($this->debug) {
|
||||
Notice::note('already grapped lineups.json', 'y');
|
||||
@@ -124,15 +122,15 @@ trait GrappingEvent
|
||||
* EVENT odds
|
||||
*********************************/
|
||||
|
||||
if (! $this->grapped($base_check_string.'/odds.json')) {
|
||||
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) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$this->sleep();
|
||||
$this->grapper_sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
@@ -148,22 +146,21 @@ trait GrappingEvent
|
||||
* EVENT incidents
|
||||
*********************************/
|
||||
|
||||
if (! $this->grapped($base_check_string.'/incidents.json')) {
|
||||
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) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$this->sleep();
|
||||
$this->grapper_sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put("$folder/incidents.json", json_encode($data));
|
||||
|
||||
} else {
|
||||
if ($this->debug) {
|
||||
Notice::note('already grapped incidents.json', 'y');
|
||||
@@ -178,14 +175,14 @@ trait GrappingEvent
|
||||
'grapper_id' => $this->task_id,
|
||||
'day' => $day,
|
||||
'liga' => $event['tournament']['name'],
|
||||
'name' => $event['homeTeam']['name'].' vs '.$event['awayTeam']['name'],
|
||||
'name' => $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'],
|
||||
'url' => $url,
|
||||
'starttime' => $starttime->toDateTimeString(),
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
if ($this->debug) {
|
||||
Notice::note('grapped: '.$base_check_string, 'p');
|
||||
Notice::note('grapped: ' . $base_check_string, 'p');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,7 +192,7 @@ trait GrappingEvent
|
||||
}
|
||||
}
|
||||
if ($this->debug) {
|
||||
Notice::note($day.' - '.$tournament['tournament']['name'].' no events', 'y');
|
||||
Notice::note($day . ' - ' . $tournament['tournament']['name'] . ' no events', 'y');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ trait GrappingSofascore
|
||||
protected int $debug;
|
||||
|
||||
protected int $restart;
|
||||
protected int $speed;
|
||||
|
||||
protected int $force;
|
||||
|
||||
@@ -59,60 +60,54 @@ trait GrappingSofascore
|
||||
|
||||
$this->force = $this->options()['f'] ?? 0;
|
||||
|
||||
switch ($this->getName()) {
|
||||
case 'grp:daily':
|
||||
$grapperSelected = $this->select_grapper();
|
||||
|
||||
$this->set_base_dir($grapperSelected);
|
||||
|
||||
switch ($grapperSelected) {
|
||||
case 'daily':
|
||||
$this->daily_grapper_nobreak();
|
||||
break;
|
||||
|
||||
default:
|
||||
// code...
|
||||
case 'back':
|
||||
$this->task_id = 1;
|
||||
$this->days_back = (int) $this->select_day();
|
||||
$this->run_days_back($grapperSelected);
|
||||
break;
|
||||
|
||||
$grapperSelected = $this->select_grapper();
|
||||
case 'range':
|
||||
$this->task_id = 3;
|
||||
$this->range_grapper_nobreak();
|
||||
break;
|
||||
|
||||
$this->set_base_dir($grapperSelected);
|
||||
case 'rose':
|
||||
$this->team_rose();
|
||||
break;
|
||||
|
||||
switch ($grapperSelected) {
|
||||
case 'daily':
|
||||
$this->task_id = 1;
|
||||
$this->days_back = (int) $this->select_day();
|
||||
$this->run_daily($grapperSelected);
|
||||
break;
|
||||
case 'settings':
|
||||
$this->settings_to_local();
|
||||
break;
|
||||
|
||||
case 'range':
|
||||
$this->task_id = 3;
|
||||
$this->range_grapper_nobreak();
|
||||
break;
|
||||
case 'excel':
|
||||
$folder = $this->select_folder();
|
||||
|
||||
case 'rose':
|
||||
$this->team_rose();
|
||||
break;
|
||||
$this->import_to_excel($folder);
|
||||
break;
|
||||
|
||||
case 'settings':
|
||||
$this->settings_to_local();
|
||||
break;
|
||||
case 'mail':
|
||||
$folder = $this->select_folder();
|
||||
|
||||
case 'excel':
|
||||
$folder = $this->select_folder();
|
||||
$this->send($folder);
|
||||
break;
|
||||
|
||||
$this->import_to_excel($folder);
|
||||
break;
|
||||
case 'clear':
|
||||
$folder = $this->select_folder();
|
||||
|
||||
case 'mail':
|
||||
$folder = $this->select_folder();
|
||||
$this->clear_folder($folder);
|
||||
break;
|
||||
|
||||
$this->send($folder);
|
||||
break;
|
||||
|
||||
case 'clear':
|
||||
$folder = $this->select_folder();
|
||||
|
||||
$this->clear_folder($folder);
|
||||
break;
|
||||
|
||||
case 'delete_orphants':
|
||||
$this->delete_imported_files_orphants();
|
||||
break;
|
||||
}
|
||||
case 'delete_orphants':
|
||||
$this->delete_imported_files_orphants();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -133,6 +128,13 @@ trait GrappingSofascore
|
||||
$this->load_tournaments_requested($folder);
|
||||
|
||||
$restart = $this->ask_restart();
|
||||
|
||||
$this->speed = $this->ask_speed();
|
||||
|
||||
if ($this->ask_settings_download()) {
|
||||
$this->settings_to_local();
|
||||
}
|
||||
|
||||
switch ($restart) {
|
||||
case 'restart':
|
||||
$this->restart = 1;
|
||||
@@ -156,7 +158,7 @@ trait GrappingSofascore
|
||||
$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->grapped_files = $this->get_tree($this->data_dir . '/' . $day);
|
||||
|
||||
$this->grap_tournaments_for_day($day);
|
||||
|
||||
@@ -174,7 +176,7 @@ trait GrappingSofascore
|
||||
|
||||
if (! $res) {
|
||||
|
||||
$this->grapped_files = $this->get_tree($this->data_dir.'/'.$day);
|
||||
$this->grapped_files = $this->get_tree($this->data_dir . '/' . $day);
|
||||
|
||||
$this->grap_tournaments_for_day($day);
|
||||
|
||||
@@ -196,14 +198,16 @@ trait GrappingSofascore
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary of run_daily
|
||||
* Summary of run_days_back
|
||||
*/
|
||||
protected function run_daily(string $grapperSelected)
|
||||
protected function run_days_back(string $grapperSelected)
|
||||
{
|
||||
$this->load_tournaments_requested($grapperSelected);
|
||||
|
||||
$this->load_days($grapperSelected);
|
||||
|
||||
$this->speed = $this->ask_speed();
|
||||
|
||||
if ($this->confirm($this->days[0], true)) {
|
||||
|
||||
foreach ($this->days as $day) {
|
||||
@@ -247,6 +251,8 @@ trait GrappingSofascore
|
||||
break;
|
||||
}
|
||||
|
||||
$this->speed = $this->ask_speed();
|
||||
|
||||
$day_done = $this->days_done();
|
||||
|
||||
$this->load_tournaments_requested($folder);
|
||||
@@ -302,7 +308,8 @@ trait GrappingSofascore
|
||||
label: 'What task should run?',
|
||||
scroll: 10,
|
||||
options: [
|
||||
'daily' => 'Select day back',
|
||||
'daily' => 'Daily run',
|
||||
'back' => 'Select day back',
|
||||
'range' => 'Range',
|
||||
'rose' => 'Rose Teams',
|
||||
'player' => 'Player',
|
||||
@@ -332,6 +339,8 @@ trait GrappingSofascore
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function select_day(): string
|
||||
{
|
||||
return text(
|
||||
@@ -353,7 +362,18 @@ trait GrappingSofascore
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function ask_speed(): int
|
||||
{
|
||||
return select(
|
||||
label: 'How fast you want to go?',
|
||||
default: 1,
|
||||
options: [
|
||||
1 => 'Fast (5 -10 sec)',
|
||||
2 => 'Middle (10 - 20 sec)',
|
||||
3 => 'Slow (30 - 50 sec)',
|
||||
]
|
||||
);
|
||||
}
|
||||
protected function select_what_delete(): string
|
||||
{
|
||||
return select(
|
||||
@@ -365,4 +385,16 @@ trait GrappingSofascore
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function ask_settings_download(): string
|
||||
{
|
||||
return select(
|
||||
label: 'Download setting?',
|
||||
default: 0,
|
||||
options: [
|
||||
0 => 'No',
|
||||
1 => 'Yes',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Traits\Sofascore;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\Strings;
|
||||
use App\Models\SofaScoreRosa;
|
||||
use App\Models\SofaScoreRosaTournament;
|
||||
use App\Models\SofaScoreTournament;
|
||||
@@ -59,7 +58,7 @@ trait GrappingTeams
|
||||
echo "\n$key/$count\n";
|
||||
}
|
||||
|
||||
$url = $this->base_url."api/v1/team/$value->ss_team_id/players";
|
||||
$url = $this->base_url . "api/v1/team/$value->ss_team_id/players";
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note($url, 'b');
|
||||
@@ -75,11 +74,11 @@ trait GrappingTeams
|
||||
* add team to folder
|
||||
*********************************/
|
||||
|
||||
File::put($this->data_dir.'/'.Strings::clean($value->ss_team_name).'.json', json_encode($data));
|
||||
File::put($this->data_dir . '/' . $this->clean_string($value->ss_team_name) . '.json', json_encode($data));
|
||||
|
||||
SofaScoreRosa::where('id', $value->id)->update(['grapped' => 1]);
|
||||
|
||||
$this->sleep();
|
||||
$this->grapper_sleep($this->speed);
|
||||
}
|
||||
|
||||
$this->import_to_excel("rose_$what");
|
||||
|
||||
@@ -21,7 +21,7 @@ trait GrappingTournaments
|
||||
$sport_id = 1;
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note('⚽ tournaments for day '.$day);
|
||||
Notice::note('⚽ tournaments for day ' . $day);
|
||||
Notice::note('⚽ close all vpn');
|
||||
}
|
||||
exec('killall ssh');
|
||||
@@ -59,9 +59,9 @@ trait GrappingTournaments
|
||||
while ($page) {
|
||||
// $data = $this->curl($url);
|
||||
|
||||
$this->sleep();
|
||||
$this->grapper_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";
|
||||
|
||||
$cloudflareService = new CloudflareSolverService;
|
||||
|
||||
|
||||
Reference in new issue
Block a user