diff --git a/README.md b/README.md index 72c1a0d..d3be704 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,9 @@ ## Project start -1. Run `migration.php` file to create `database.sqlite` and create tables. -2. Run `php index.php app:scrape` command to scrape all the products from the ryobi website. \ No newline at end of file +1. Clone repository using `git clone https://git.techtube.pl/krzysiej/ryobi-crawler.git` +2. Cd into project directory `cd ryobi-crawler` +3. Build and start docker container `docker compose up -d` +4. Run `docker compose exec php-app php index.php app:migrate` file to create `database.sqlite` and create tables. +5. Run `docker compose exec php-app php index.php app:scrape` command to scrape all the products from the ryobi website. +6. Access web interface using `localhost:9000` address in web browser. \ No newline at end of file diff --git a/browser.php b/browser.php index 18ff0ff..47185e1 100644 --- a/browser.php +++ b/browser.php @@ -6,6 +6,10 @@ use Illuminate\Database\Capsule\Manager as Capsule; use Krzysiej\RyobiCrawler\Models\Product; use Twig\{Environment, Loader\FilesystemLoader}; +if (!file_exists('database.sqlite')) { + exit('Database file database.sqlite missing. Run docker compose
docker compose exec php-app php index.php app:migrate
to create it.'); +} + $capsule = new Capsule; $capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/database.sqlite']); $capsule->setAsGlobal(); diff --git a/index.php b/index.php index 6d364c9..c18dca1 100644 --- a/index.php +++ b/index.php @@ -13,7 +13,7 @@ if (php_sapi_name() !== 'cli') { exit; } -$application = new Application('Ryobi website scraper application', '1.1.0'); +$application = new Application('Ryobi website scraper application', '1.1.1'); $application->add(new ScrapeWebsite()); $application->add(new Migrate()); $application->run(); diff --git a/migration.php b/migration.php deleted file mode 100644 index 3a7fe3c..0000000 --- a/migration.php +++ /dev/null @@ -1,49 +0,0 @@ -addConnection([ - 'driver' => 'sqlite', - 'database' => __DIR__ . '/database.sqlite', -]); -$capsule->setAsGlobal(); - -if (!Capsule::schema()->hasTable('products')) { - Capsule::schema()->create('products', function (Blueprint $table) { - $table->increments('id'); - $table->string('name'); - $table->integer('skuID')->unique(); - $table->integer('agilityID'); - $table->integer('availableQuantity'); - $table->integer('stock'); - $table->json('categories'); - $table->string('image'); - $table->string('subTitle'); - $table->string('variantCode'); - $table->string('modelCode'); - $table->string('url'); - $table->boolean('starred')->default(false); - $table->timestamps(); - }); -} - - -if (!Capsule::schema()->hasTable('prices')) { - Capsule::schema()->create('prices', function (Blueprint $table) { - $table->increments('id'); - $table->foreignId('product_id'); - $table->float('price'); - $table->float('productStandardPrice'); - $table->float('lowestProductPrice30Days'); - $table->timestamps(); - }); -}