asrock-memory-qvl-scraper/bin/app.php

35 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2021-04-22 19:26:09 +02:00
<?php
use Domain\Model\ASRockMemoryQVL;
use Domain\Model\MemoryConfiguration;
2021-04-28 20:17:37 +02:00
use Domain\Normalizer\Decorator\TweakersPricewatchUrl;
2021-04-22 19:26:09 +02:00
use Domain\Normalizer\MemoryConfigurationNormalizer;
use Encoder\EncoderFactory;
use IO\Downloader;
require_once __DIR__ . '/../vendor/autoload.php';
// setup
2021-04-28 20:17:37 +02:00
$qualifiedVendorList = new ASRockMemoryQVL('AMD', 'X570 Pro4', cpuFamily: 'MS');
2021-04-22 19:26:09 +02:00
$downloader = new Downloader();
$scraper = new MemoryQVLScraper();
// scrape and filter
2021-04-28 20:17:37 +02:00
$page = $downloader->download($qualifiedVendorList);
2021-04-22 19:26:09 +02:00
$configurations = $scraper->scrape($page);
2021-04-28 20:17:37 +02:00
$selection = $configurations->filter(static function (MemoryConfiguration $memory) {
2021-04-28 20:26:18 +02:00
return in_array($memory->numberOfModules, [2, 4])
2021-04-22 19:26:09 +02:00
&& $memory->totalSize >= 16
&& $memory->speed >= 3600
2021-04-28 20:17:37 +02:00
&& $memory->overclockingVerified;
});
2021-04-22 19:26:09 +02:00
// data presentation
$normalizer = new MemoryConfigurationNormalizer();
2021-04-28 20:17:37 +02:00
$normalizer = TweakersPricewatchUrl::decorate($normalizer);
2021-04-22 19:26:09 +02:00
$encoderFactory = new EncoderFactory($normalizer);
2021-04-28 20:17:37 +02:00
$encoding = $argv[1] ?? 'csv';
$encoder = $encoderFactory->getEncoder($encoding);
2021-04-22 19:26:09 +02:00
print($encoder->encode($selection));