diff options
Diffstat (limited to 'app/Console/Commands')
| -rw-r--r-- | app/Console/Commands/ScrapeFile.php | 59 | ||||
| -rw-r--r-- | app/Console/Commands/ScrapeFiles.php | 64 | ||||
| -rw-r--r-- | app/Console/Commands/ScrapeUrl.php | 61 | 
3 files changed, 184 insertions, 0 deletions
| diff --git a/app/Console/Commands/ScrapeFile.php b/app/Console/Commands/ScrapeFile.php new file mode 100644 index 0000000..4cfef90 --- /dev/null +++ b/app/Console/Commands/ScrapeFile.php @@ -0,0 +1,59 @@ +<?php + +namespace App\Console\Commands; + +use App\Rugby\Factory\Service; +use App\Rugby\Factory\SixnationsrugbyAdapter; +use Illuminate\Console\Command; +use Illuminate\Support\Facades\Storage; + +class ScrapeFile extends Command +{ +    /** +     * The name and signature of the console command. +     * +     * @var string +     */ +    protected $signature = 'scrape:file { filename }'; + +    /** +     * The console command description. +     * +     * @var string +     */ +    protected $description = 'Scrape a file for data'; + +    /** +     * Create a new command instance. +     * +     * @return void +     */ +    public function __construct() +    { +        parent::__construct(); +    } + +    /** +     * Execute the console command. +     * +     * @return mixed +     */ +    public function handle() +    { +        $filename = $this->argument('filename'); + +        if (!Storage::disk('local')->exists($filename)) { +            $this->error('Could not load file at: ' . Storage::disk('local')->path($filename)); +            return Command::FAILURE; +        } + +        $raw_data = Storage::disk('local')->get($filename); + +        $service = new Service(new SixnationsrugbyAdapter($raw_data, 'Six Nations')); + +        $service->save(); + +        return Command::SUCCESS; +    } + +} diff --git a/app/Console/Commands/ScrapeFiles.php b/app/Console/Commands/ScrapeFiles.php new file mode 100644 index 0000000..05b7176 --- /dev/null +++ b/app/Console/Commands/ScrapeFiles.php @@ -0,0 +1,64 @@ +<?php + +namespace App\Console\Commands; + +use App\Rugby\Factory\Service; +use App\Rugby\Factory\SixnationsrugbyAdapter; +use Illuminate\Console\Command; +use Illuminate\Support\Facades\Storage; + +class ScrapeFiles extends Command +{ +    /** +     * The name and signature of the console command. +     * +     * @var string +     */ +    protected $signature = 'scrape:files { directory }'; + +    /** +     * The console command description. +     * +     * @var string +     */ +    protected $description = 'Scrape a file for data'; + +    /** +     * Create a new command instance. +     * +     * @return void +     */ +    public function __construct() +    { +        parent::__construct(); +    } + +    /** +     * Execute the console command. +     * +     * @return mixed +     */ +    public function handle() +    { +        $directory = $this->argument('directory'); + +        if (!Storage::disk('local')->exists($directory)) { +            $this->error('Could not load file at: ' . Storage::disk('local')->path($directory)); +            return Command::FAILURE; +        } + +        $files = Storage::disk('local')->files($directory); + + +        foreach ($files as $file) { +            $tournament = 'Six Nations ' . explode('-', explode('.txt', $file)[0])[1]; +            $raw_data = Storage::disk('local')->get($file); + +            $service = new Service(new SixnationsrugbyAdapter($raw_data, $tournament)); +            $service->save(); +        } + +        return Command::SUCCESS; +    } + +} diff --git a/app/Console/Commands/ScrapeUrl.php b/app/Console/Commands/ScrapeUrl.php new file mode 100644 index 0000000..c02080e --- /dev/null +++ b/app/Console/Commands/ScrapeUrl.php @@ -0,0 +1,61 @@ +<?php + +namespace App\Console\Commands; + +use Illuminate\Console\Command; +use Goutte\Client; + +class ScrapeUrl extends Command +{ +    /** +     * The name and signature of the console command. +     * +     * @var string +     */ +    protected $signature = 'scrape:url { url }'; + +    /** +     * The console command description. +     * +     * @var string +     */ +    protected $description = 'Scrape a webpage for data'; + +    protected $client; + +    /** +     * Create a new command instance. +     * +     * @return void +     */ +    public function __construct() +    { +        parent::__construct(); +        $this->client = new Client(); +    } + +    /** +     * Execute the console command. +     * +     * @return mixed +     */ +    public function handle() +    { +        $url = $this->argument('url'); + +        if ($url != 'https://www.sixnationsrugby.com/fixtures/') { +            $this->error('Url not supported'); +            return; +        } + +        $crawler = $this->client->request('GET', $this->argument('url')); + +        $crawler->filter('div.fixtures__top-tier')->each( +            function ($node) { +                print $node->text()."\n"; +            } +        ); + + +    } +} | 
