speed = $this->ask_speed(); switch ($this->ask_restart()) { case 'clear': SofaScoreRosa::query()->update(['grapped' => 0]); File::cleanDirectory($this->data_dir); break; case 'restart': SofaScoreRosa::query()->update(['grapped' => 0]); break; default: // code... break; } switch ($title = $this->select_what_to_grap()) { case 'major': $tournaments = SofaScoreTournament::where('enabled', 1)->whereIn('tournament_id', $major)->pluck('tournament_id')->toArray(); break; case 'others': $tournaments = SofaScoreTournament::where('enabled', 1)->whereNotIn('tournament_id', $major)->pluck('tournament_id')->toArray(); break; default: $tmp = self::load_tornament_ids(); $title = 'rose_'.str_replace(',', '_', $tmp); $tournaments = explode(',', $tmp); 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++; Notice::note($key.'/'.$count.' - '.$value->ss_team_name); } $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', $title); 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', 'manual' => 'Enter team_ids (sofa_score_rosas)', ] ); } protected function load_tornament_ids(): string { return text( label: 'Enter CSV Team Id (from table sofa_score_rosas)', default: '', ); } }