Change url naming convention. Update README.md
This commit is contained in:
11
README.md
11
README.md
@@ -5,10 +5,17 @@
|
||||
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.
|
||||
4. Run `docker compose exec php-app php console.php app:migrate` file to create `database.sqlite` and create tables.
|
||||
5. Run `docker compose exec php-app php console.php app:scrape` command to scrape all the products from the ryobi website.
|
||||
6. Access web interface using `localhost:9000` address in web browser.
|
||||
|
||||
|
||||
## Update project
|
||||
|
||||
1. Cd into project directory
|
||||
2. Run `git pull`
|
||||
3. Start and build image in one go with command: `docker compose up -d --build --force-recreate`
|
||||
|
||||
## Screenshots
|
||||
|
||||
### Main screen of the web view
|
||||
|
||||
48
browser.php
48
browser.php
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
include_once 'vendor/autoload.php';
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Krzysiej\RyobiCrawler\Controller\CategoryController;
|
||||
use Krzysiej\RyobiCrawler\Controller\IndexController;
|
||||
use Krzysiej\RyobiCrawler\Controller\ProductController;
|
||||
use Krzysiej\RyobiCrawler\Controller\SearchController;
|
||||
use Krzysiej\RyobiCrawler\Controller\StarController;
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Twig\{Environment, Loader\FilesystemLoader};
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
if (!file_exists('database.sqlite')) {
|
||||
exit('Database file <code>database.sqlite</code> missing. Run docker compose <blockquote>docker compose exec php-app php index.php app:migrate</blockquote> to create it.');
|
||||
}
|
||||
$productRoute = new Route('/browser.php/product/{product_id}', ['_controller' => ProductController::class], ['product_id' => '\d+']);
|
||||
$searchRoute = new Route('/browser.php?search={search_term}', ['_controller' => SearchController::class]);
|
||||
$categoryRoute = new Route('/browser.php/category/{category_name}', ['_controller' => CategoryController::class]);
|
||||
$starRoute = new Route('/browser.php/star/{product_id}', ['_controller' => StarController::class]);
|
||||
$indexRoute = new Route('/browser.php', ['_controller' => IndexController::class]);
|
||||
$routes = new RouteCollection();
|
||||
|
||||
$routes->add('product_show', $productRoute);
|
||||
$routes->add('search_show', $searchRoute);
|
||||
$routes->add('category_show', $categoryRoute);
|
||||
$routes->add('start_show', $starRoute);
|
||||
$routes->add('index_show', $indexRoute);
|
||||
|
||||
$context = new RequestContext();
|
||||
$matcher = new UrlMatcher($routes, $context);
|
||||
try {
|
||||
$parameters = $matcher->match($_SERVER['REQUEST_URI']);
|
||||
} catch (Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
match ($parameters['_controller']) {
|
||||
SearchController::class => (new $parameters['_controller']())($parameters['search_term']),
|
||||
CategoryController::class => (new $parameters['_controller']())($parameters['category_name']),
|
||||
ProductController::class, StarController::class => (new $parameters['_controller']())($parameters['product_id']),
|
||||
IndexController::class => (new $parameters['_controller']())(),
|
||||
default => throw new Exception('Route not found')
|
||||
};
|
||||
19
console.php
Normal file
19
console.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
include_once 'vendor/autoload.php';
|
||||
|
||||
use Krzysiej\RyobiCrawler\Command\Migrate;
|
||||
use Krzysiej\RyobiCrawler\Command\ScrapeWebsite;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
header('Location: browser.php');
|
||||
echo 'Execute this script in cli only';
|
||||
exit;
|
||||
}
|
||||
|
||||
$application = new Application('Ryobi website scraper application', '1.1.1');
|
||||
$application->add(new ScrapeWebsite());
|
||||
$application->add(new Migrate());
|
||||
$application->run();
|
||||
48
index.php
48
index.php
@@ -2,18 +2,44 @@
|
||||
|
||||
include_once 'vendor/autoload.php';
|
||||
|
||||
use Krzysiej\RyobiCrawler\Command\Migrate;
|
||||
use Krzysiej\RyobiCrawler\Command\ScrapeWebsite;
|
||||
use Krzysiej\RyobiCrawler\Controller\CategoryController;
|
||||
use Krzysiej\RyobiCrawler\Controller\IndexController;
|
||||
use Krzysiej\RyobiCrawler\Controller\ProductController;
|
||||
use Krzysiej\RyobiCrawler\Controller\SearchController;
|
||||
use Krzysiej\RyobiCrawler\Controller\StarController;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
if (!file_exists('database.sqlite')) {
|
||||
exit('Database file <code>database.sqlite</code> missing. Run docker compose <blockquote>docker compose exec php-app php index.php app:migrate</blockquote> to create it.');
|
||||
}
|
||||
$productRoute = new Route('/product/{product_id}', ['_controller' => ProductController::class], ['product_id' => '\d+']);
|
||||
$searchRoute = new Route('/?search={search_term}', ['_controller' => SearchController::class]);
|
||||
$categoryRoute = new Route('/category/{category_name}', ['_controller' => CategoryController::class]);
|
||||
$starRoute = new Route('/star/{product_id}', ['_controller' => StarController::class]);
|
||||
$indexRoute = new Route('/', ['_controller' => IndexController::class]);
|
||||
$routes = new RouteCollection();
|
||||
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
header('Location: browser.php');
|
||||
echo 'Execute this script in cli only';
|
||||
exit;
|
||||
$routes->add('product_show', $productRoute);
|
||||
$routes->add('search_show', $searchRoute);
|
||||
$routes->add('category_show', $categoryRoute);
|
||||
$routes->add('start_show', $starRoute);
|
||||
$routes->add('index_show', $indexRoute);
|
||||
|
||||
$context = new RequestContext();
|
||||
$matcher = new UrlMatcher($routes, $context);
|
||||
try {
|
||||
$parameters = $matcher->match($_SERVER['REQUEST_URI']);
|
||||
} catch (Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
$application = new Application('Ryobi website scraper application', '1.1.1');
|
||||
$application->add(new ScrapeWebsite());
|
||||
$application->add(new Migrate());
|
||||
$application->run();
|
||||
match ($parameters['_controller']) {
|
||||
SearchController::class => (new $parameters['_controller']())($parameters['search_term']),
|
||||
CategoryController::class => (new $parameters['_controller']())($parameters['category_name']),
|
||||
ProductController::class, StarController::class => (new $parameters['_controller']())($parameters['product_id']),
|
||||
IndexController::class => (new $parameters['_controller']())(),
|
||||
default => throw new Exception('Route not found')
|
||||
};
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
{% block content %}
|
||||
<table class='table table-hover'>
|
||||
<tr>
|
||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none" href="/browser.php/star/{{ product.id }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none" href="/star/{{ product.id }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
||||
<td><img src='{{ product.image }}&width=150' class='img-fluid' alt='{{ product.name }}'/></td>
|
||||
<td><a href='/browser.php/product/{{ product.id }}'>{{ product.name }}</a></td>
|
||||
<td><a href='/product/{{ product.id }}'>{{ product.name }}</a></td>
|
||||
<td>{{ product.subTitle }}</td>
|
||||
<td>
|
||||
<ul class='nav'>
|
||||
{% for category in product.categories %}
|
||||
<li class="nav-item"><a class="nav-link" href="/browser.php/category/{{ category }}"> {{ category }} </a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/category/{{ category }}"> {{ category }} </a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
<table class='table table-hover'>
|
||||
{% for product in products %}
|
||||
<tr>
|
||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none" href="/browser.php/star/{{ product.id }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none" href="/star/{{ product.id }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
||||
<td><img src='{{ product.image }}&width=70' class='img-fluid' alt='{{ product.name }}'/></td>
|
||||
<td class="align-middle"><a href='/browser.php/product/{{ product.id }}'>{{ product.name }}</a></td>
|
||||
<td class="align-middle"><a href='/product/{{ product.id }}'>{{ product.name }}</a></td>
|
||||
<td class="align-middle">{{ product.subTitle }}</td>
|
||||
<td class="align-middle">
|
||||
<ul class='nav'>
|
||||
{% for category in product.categories %}
|
||||
<li class="nav-item"><a class="nav-link" href="/browser.php/category/{{ category }}"> {{ category }} </a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/category/{{ category }}"> {{ category }} </a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
<body>
|
||||
<nav class="navbar sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/browser.php">Crawler</a>
|
||||
<form class="d-flex w-50" role="search">
|
||||
<a class="navbar-brand" href="/">Crawler</a>
|
||||
<form class="d-flex w-50" role="search" action="/">
|
||||
<input class="form-control me-2" type="search" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search }}" aria-label="Search">
|
||||
<button class="btn btn-outline-success" type="submit">Search</button>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user