select_what_to_grap(); if ($this->restart) { SofaScoreRosa::query()->update(['grapped' => 0]); File::cleanDirectory($this->data_dir); } 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 . '/' . $this->clean_string($value->ss_team_name) . '.json', json_encode($data)); SofaScoreRosa::where('id', $value->id)->update(['grapped' => 1]); $this->grapper_sleep($this->speed); } $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', ] ); } }