diff --git a/bin/moonboard-web-scraper b/bin/moonboard-web-scraper index 333e836..9363740 100755 --- a/bin/moonboard-web-scraper +++ b/bin/moonboard-web-scraper @@ -34,6 +34,7 @@ $application->add(new ScrapeBenchmarksCommand( authenticator: new Authenticator( username: getenv('MOONBOARD_USERNAME'), password: getenv('MOONBOARD_PASSWORD'), + logger: $logger, ), holdSetups: HoldSetups::all(), logger: $logger, diff --git a/src/Services/Authenticator.php b/src/Services/Authenticator.php index 57855d2..2d8d1db 100644 --- a/src/Services/Authenticator.php +++ b/src/Services/Authenticator.php @@ -4,6 +4,7 @@ namespace App\Services; +use Psr\Log\LoggerInterface; use Symfony\Component\Panther\Client; class Authenticator @@ -11,10 +12,13 @@ class Authenticator public function __construct( private readonly string $username, private readonly string $password, + private readonly LoggerInterface $logger, ) {} public function authenticate(Client $client): void { + $this->logger->info('Authenticating...'); + $client->request('GET', '/'); $client->executeScript("$('#loginDropdown').click()"); diff --git a/src/UseCases/ScrapeBenchmarksAction.php b/src/UseCases/ScrapeBenchmarksAction.php index d5ff7bc..e88b935 100644 --- a/src/UseCases/ScrapeBenchmarksAction.php +++ b/src/UseCases/ScrapeBenchmarksAction.php @@ -38,6 +38,11 @@ public function __invoke(): void */ private function getProblemUrls(HoldSetup $holdSetup): array { + $this->logger->info('Scraping problem URLs...', [ + 'boardType' => $holdSetup->getBoardType()->getLabel(), + 'boardAngle' => $holdSetup->getBoardAngle()->getLabel(), + ]); + $this->client->request('GET', '/Dashboard/Index'); $this->client->executeScript("$('#Holdsetup').val('".$holdSetup->getBoardType()->value."').change()"); $this->client->executeScript("$('[data-id=\"".$holdSetup->getBoardAngle()->value."\"]').click()"); @@ -99,8 +104,11 @@ private function getProblemUrls(HoldSetup $holdSetup): array private function getProblemData(array $problemUrls): array { $problemData = []; + $problemUrlCount = \count($problemUrls); + + foreach ($problemUrls as $i => $problemUrl) { + $this->logger->info('Scraping problem data... ('.($i + 1).'/'.$problemUrlCount.')', ['problemUrl' => $problemUrl]); - foreach ($problemUrls as $problemUrl) { $this->client->request('GET', $problemUrl); $crawler = $this->client->getCrawler(); @@ -136,6 +144,11 @@ private function getProblemData(array $problemUrls): array */ private function saveProblemData(array $problemData, HoldSetup $holdSetup): void { + $this->logger->info('Saving problem data...', [ + 'boardType' => $holdSetup->getBoardType()->getLabel(), + 'boardAngle' => $holdSetup->getBoardAngle()->getLabel(), + ]); + file_put_contents( sprintf('problems %s %s.json', $holdSetup->getBoardType()->getLabel(), $holdSetup->getBoardAngle()->getLabel()), json_encode($problemData, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),