blob: e80e9e25fc9c20f6e79b3ee528c25dc423be2636 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<?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
{
protected $signature = 'scrape:files { directory }';
protected $description = 'Scrape a file for data';
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) {
$this->info('Starting file: ' . $file);
$raw_data = Storage::disk('local')->get($file);
$tournament = 'Six Nations ' . explode('-', explode('.txt', $file)[0])[1];
$service = new Service(new SixnationsrugbyAdapter($raw_data, $tournament));
$service->save();
}
return Command::SUCCESS;
}
}
|