wip
This commit is contained in:
1 parent
acf1b78c47
commit
03b3d47151
7 files changed
+129
-34
No files matched your search
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits\Sofascore;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\Strings;
|
||||
use App\Models\SofaScoreRosa;
|
||||
use App\Models\SofaScoreRosaTournament;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Services\CloudflareSolverService;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
use function Laravel\Prompts\select;
|
||||
|
||||
trait GrappingTeams
|
||||
{
|
||||
protected int $max = 2000;
|
||||
|
||||
public function team_rose()
|
||||
{
|
||||
// LaLiga 8
|
||||
// Ita A 23
|
||||
// Ita B 53
|
||||
// Eng Prem 17
|
||||
// Bundesliga 35
|
||||
// FRA Ligue 1 34
|
||||
// ENG1, ESP1, ITA1, ITA2, FRA1 e GER1
|
||||
$major = [8, 17, 23, 34, 35, 53];
|
||||
|
||||
$what = $this->select_what_to_grap();
|
||||
|
||||
if ($this->restart) {
|
||||
SofaScoreRosa::query()->update(['grapped' => 0]);
|
||||
$this->clear_folder($this->data_dir, 'all');
|
||||
}
|
||||
|
||||
switch ($what) {
|
||||
case 'major':
|
||||
$tournaments = SofaScoreTournament::where('enabled', 1)->whereIn('tournament_id', $major)->pluck('tournament_id')->toArray();
|
||||
break;
|
||||
|
||||
default:
|
||||
$tournaments = SofaScoreTournament::where('enabled', 1)->whereNotIn('tournament_id', $major)->pluck('tournament_id')->toArray();
|
||||
break;
|
||||
}
|
||||
|
||||
$tmp = SofaScoreRosaTournament::whereIn('ss_tournament_id', $tournaments)->pluck('ss_team_id')->toArray();
|
||||
|
||||
$teams = SofaScoreRosa::where('is_active', 1)->whereIn('ss_team_id', $tmp)->where('grapped', 0)->get();
|
||||
|
||||
$count = \count($teams);
|
||||
|
||||
$cloudflareService = new CloudflareSolverService;
|
||||
|
||||
foreach ($teams as $key => $value) {
|
||||
|
||||
if ($this->debug) {
|
||||
$key++;
|
||||
echo "\n$key/$count\n";
|
||||
}
|
||||
|
||||
$url = $this->base_url."api/v1/team/$value->ss_team_id/players";
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['ss_team_id'] = $value->ss_team_id;
|
||||
|
||||
$data['ss_team_name'] = $value->ss_team_name;
|
||||
|
||||
/*********************************
|
||||
* add team to folder
|
||||
*********************************/
|
||||
|
||||
File::put($this->data_dir.'/'.Strings::clean($value->ss_team_name).'.json', json_encode($data));
|
||||
|
||||
SofaScoreRosa::where('id', $value->id)->update(['grapped' => 1]);
|
||||
|
||||
$this->sleep();
|
||||
}
|
||||
|
||||
$this->import_to_excel("rose_$what");
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note('DONE', 'bb');
|
||||
}
|
||||
}
|
||||
|
||||
protected function select_what_to_grap(): string
|
||||
{
|
||||
return select(
|
||||
label: 'What teams should be grapped?',
|
||||
options: [
|
||||
'major' => 'Major Leagues',
|
||||
'others' => 'Others Leagues',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user