12 Commits

Author SHA1 Message Date
3d47726a81 Merge pull request 'Promo endpoint that display only products on sale.' (#1) from feature/promo-branch into master
Reviewed-on: #1
2024-10-18 11:28:01 +02:00
Krzysztof Płaczek
fee7495cfe Promo endpoint that display only products on sale. 2024-10-18 11:24:46 +02:00
Krzysztof Płaczek
53b6d33ab9 Display price discount on items list. 2024-10-17 10:22:32 +02:00
Krzysztof Płaczek
3cc5d73758 Autostart docker app unless stopped on purpose. Update README.md and describe cron scheduling. Add chart to product view and sort product prices. 2024-10-15 20:20:57 +02:00
Krzysztof Płaczek
d043e8efb1 Change url naming convention. Update README.md 2024-10-14 14:04:15 +02:00
Krzysztof Płaczek
2b595c1403 Update star route. 2024-10-14 09:34:23 +02:00
Krzysztof Płaczek
f2e6cba2f5 Split browser.php to commands with routes. 2024-10-13 20:44:14 +02:00
Krzysztof Płaczek
e13a0acce1 Add parameter recreate to migration command. 2024-10-13 20:33:30 +02:00
Krzysztof Płaczek
77732689d8 Remove product property agilityID. 2024-10-13 12:46:56 +02:00
Krzysztof Płaczek
22cc3f699b Change port to 9001 port allocation collision. 2024-10-13 12:40:26 +02:00
Krzysztof Płaczek
a1b6d65137 Change port to avoid sentry port allocation collision. 2024-10-13 12:39:19 +02:00
Krzysztof Płaczek
7ee8df32f9 Add screenshot 2024-10-12 18:41:49 +02:00
21 changed files with 478 additions and 84 deletions

View File

@@ -5,6 +5,25 @@
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.
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:9001` 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`
## Running Cron
For now only way of running `app:scrape` command on schedule is to use host crontab.
1. Run `crontab -e` command to edit host crontab job file
2. Add a new line with e.g. line like this `0 1 * * * cd /var/project/directory/ && docker compose exec php-app php console.php app:scrape`
3. Save and exit file editor. Cron will execute `app:scrape` once per day.
## Screenshots
### Main screen of the web view
![Main screen of the web view](screenshot1.png)

View File

@@ -1,42 +0,0 @@
<?php
include_once 'vendor/autoload.php';
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 <code>database.sqlite</code> missing. Run docker compose <blockquote>docker compose exec php-app php index.php app:migrate</blockquote> to create it.');
}
$capsule = new Capsule;
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/database.sqlite']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
$loader = new FilesystemLoader(__DIR__ . '/src/templates');
$twig = new Environment($loader);
if (isset($_GET['product_id'])) {
$template = 'product.html.twig';
$product = Product::with('price')->find($_GET['product_id']);
}
if (isset($_GET['category'])) {
$template = 'productList.html.twig';
$products = Product::with('price')->selectRaw('products.*')->fromRaw('products, json_each(products.categories)')->whereRaw('json_each.value = ?', [$_GET['category']])
->orderByDesc('starred')->orderByDesc('created_by')->get();
}
if (isset($_GET['search'])) {
$template = 'productList.html.twig';
$products = Product::with('price')
->orWhere([['name', 'like', "%{$_GET['search']}%"]])
->orWhere([['subTitle', 'like', "%{$_GET['search']}%"]])->get();
}
if (isset($_GET['star'])) {
Product::find($_GET['star'])->toggleStarred()->save();
header('Location: '.$_SERVER['HTTP_REFERER']);
}
if (empty($_GET)) {
$template = 'productList.html.twig';
$products = Product::with('price')->orderByDesc('starred')->orderByDesc('created_by')->get();
}
$twig->display($template, ['products' => $products ?? [], 'product' => $product ?? [], 'search' => $_GET['search'] ?? '']);

View File

@@ -5,7 +5,9 @@
"illuminate/database": "11.26.0.0",
"ext-json": "*",
"twig/twig": "3.14.0.0",
"symfony/console": "^7.0"
"symfony/console": "^7.0",
"symfony/routing": "^7.1",
"laravel/serializable-closure": "^1.3"
},
"autoload": {
"psr-4": {

146
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e9489916095593f696613b706467239b",
"content-hash": "0857f170e12b9885e20a632ba9c5d530",
"packages": [
{
"name": "brick/math",
@@ -942,6 +942,67 @@
},
"time": "2024-10-08T18:54:07+00:00"
},
{
"name": "laravel/serializable-closure",
"version": "v1.3.5",
"source": {
"type": "git",
"url": "https://github.com/laravel/serializable-closure.git",
"reference": "1dc4a3dbfa2b7628a3114e43e32120cce7cdda9c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/1dc4a3dbfa2b7628a3114e43e32120cce7cdda9c",
"reference": "1dc4a3dbfa2b7628a3114e43e32120cce7cdda9c",
"shasum": ""
},
"require": {
"php": "^7.3|^8.0"
},
"require-dev": {
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
"nesbot/carbon": "^2.61|^3.0",
"pestphp/pest": "^1.21.3",
"phpstan/phpstan": "^1.8.2",
"symfony/var-dumper": "^5.4.11|^6.2.0|^7.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Laravel\\SerializableClosure\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
},
{
"name": "Nuno Maduro",
"email": "nuno@laravel.com"
}
],
"description": "Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.",
"keywords": [
"closure",
"laravel",
"serializable"
],
"support": {
"issues": "https://github.com/laravel/serializable-closure/issues",
"source": "https://github.com/laravel/serializable-closure"
},
"time": "2024-09-23T13:33:08+00:00"
},
{
"name": "nesbot/carbon",
"version": "3.8.0",
@@ -2108,6 +2169,87 @@
],
"time": "2024-09-09T11:45:10+00:00"
},
{
"name": "symfony/routing",
"version": "v7.1.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/routing.git",
"reference": "1500aee0094a3ce1c92626ed8cf3c2037e86f5a7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/routing/zipball/1500aee0094a3ce1c92626ed8cf3c2037e86f5a7",
"reference": "1500aee0094a3ce1c92626ed8cf3c2037e86f5a7",
"shasum": ""
},
"require": {
"php": ">=8.2",
"symfony/deprecation-contracts": "^2.5|^3"
},
"conflict": {
"symfony/config": "<6.4",
"symfony/dependency-injection": "<6.4",
"symfony/yaml": "<6.4"
},
"require-dev": {
"psr/log": "^1|^2|^3",
"symfony/config": "^6.4|^7.0",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/expression-language": "^6.4|^7.0",
"symfony/http-foundation": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Routing\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Maps an HTTP request to a set of configuration variables",
"homepage": "https://symfony.com",
"keywords": [
"router",
"routing",
"uri",
"url"
],
"support": {
"source": "https://github.com/symfony/routing/tree/v7.1.4"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-08-29T08:16:25+00:00"
},
{
"name": "symfony/service-contracts",
"version": "v3.5.0",
@@ -2697,5 +2839,5 @@
"ext-json": "*"
},
"platform-dev": [],
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}

19
console.php Normal file
View 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();

View File

@@ -1,9 +1,10 @@
services:
php-app:
restart: unless-stopped
build: .
volumes:
- .:/usr/src/app
command: >
sh -c "composer install && php -S 0.0.0.0:8000 -t /usr/src/app"
ports:
- "9000:8000"
- "9001:8000"

View File

@@ -2,18 +2,48 @@
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\PromosController;
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<\d+>}', ['_controller' => ProductController::class]);
$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]);
$promosRoute = new Route('/promos', ['_controller' => PromosController::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('promos_show', $promosRoute);
$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']),
PromosController::class => (new $parameters['_controller']())(),
IndexController::class => (new $parameters['_controller']())(),
default => throw new Exception('Route not found')
};

BIN
screenshot1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

View File

@@ -9,13 +9,25 @@ use Illuminate\Database\Schema\Blueprint;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'app:migrate', description: 'Create database and rum migrations')]
class Migrate extends Command
{
private const RECREATE_OPTION = 'recreate';
protected function configure(): void
{
$this->addOption(self::RECREATE_OPTION, null, InputOption::VALUE_OPTIONAL, 'Recreate database file event if exist and has data.');
}
public function execute(InputInterface $input, OutputInterface $output): int
{
if (true === $input->hasOption(self::RECREATE_OPTION)) {
unlink(__DIR__ . '/../../database.sqlite');
//sleep(5);
}
touch(__DIR__ . '/../../database.sqlite');
$capsule = new Capsule;
$capsule->addConnection([
@@ -24,10 +36,6 @@ class Migrate extends Command
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$this->createProductsTable();
$this->createPricesTable();
$this->createStocksTable();
@@ -42,7 +50,6 @@ class Migrate extends Command
$table->increments('id');
$table->string('name');
$table->integer('skuID')->unique();
$table->integer('agilityID');
$table->integer('availableQuantity');
$table->integer('stock');
$table->json('categories');

View File

@@ -40,6 +40,7 @@ class ScrapeWebsite extends Command
$products = $this->getProducts();
$progress->setMaxSteps(count($products));
foreach ($products as $product) {
//dd($product);
$this->saveProduct($product);
$progress->advance();
}
@@ -80,11 +81,13 @@ class ScrapeWebsite extends Command
{
/** @var Product $productModel */
$productModel = Product::firstOrNew(['skuID' => $product->skuID]);
//dd($productModel);
$productModel->skuID = $product->skuID;
$productModel->name = $product->name;
$productModel->availableQuantity = $product->availableQuantity;
$productModel->stock = $product->stock;
$productModel->categories = json_encode($product->categories);
$productModel->categories = $product->categories;
$productModel->image = $product->image;
$productModel->subTitle = $product->subTitle;
$productModel->variantCode = $product->variantCode;
@@ -92,7 +95,8 @@ class ScrapeWebsite extends Command
$productModel->url = $product->url;
$productModel->save();
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
if (!$priceExists) {
if (false === $priceExists) {
$price = new Price();
$price->price = $product->productPrice;
$price->productStandardPrice = $product->productStandardPrice;
@@ -100,7 +104,7 @@ class ScrapeWebsite extends Command
$productModel->price()->save($price);
}
$stockExist = $productModel->stock()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
if (!$stockExist) {
if (false === $stockExist) {
$stock = new Stock();
$stock->availableQuantity = $product->availableQuantity;
$stock->stock = $product->stock;

View File

@@ -0,0 +1,22 @@
<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Illuminate\Database\Capsule\Manager as Capsule;
class BaseController
{
protected Environment $twig;
public function __construct()
{
$capsule = new Capsule;
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/../../database.sqlite']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
$loader = new FilesystemLoader( __DIR__ . '/../../src/templates');
$this->twig = new Environment($loader);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Krzysiej\RyobiCrawler\Models\Product;
final class CategoryController extends BaseController
{
public function __invoke(string $category): void
{
$products = Product::with('price')
->selectRaw('products.*')
->fromRaw('products, json_each(products.categories)')
->whereRaw('json_each.value = ?', [$category])
->orderByDesc('starred')
->orderByDesc('created_by')
->get();
$this->twig->display('productList.html.twig', ['products' => $products]);
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Krzysiej\RyobiCrawler\Models\Product;
final class IndexController extends BaseController
{
public function __invoke(): void
{
$products = Product::with('price')->orderByDesc('starred')->orderByDesc('created_by')->get();
$this->twig->display('productList.html.twig', ['products' => $products]);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Illuminate\Support\ItemNotFoundException;
use Krzysiej\RyobiCrawler\Models\Product;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
final class ProductController extends BaseController
{
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function __invoke(int $productId): void
{
$product = Product::with([
'price' => fn($query) => $query->orderBy('created_at', 'desc')
])->find($productId);
if(null === $product) {
throw new ItemNotFoundException('Product not found');
}
$priceList = $product->price()->pluck('price')->implode(',');
$priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->implode("','");
$this->twig->display('product.html.twig', ['product' => $product, 'price_list' => $priceList, 'price_dates' => $priceDates]);
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Illuminate\Database\Eloquent\Builder;
use Krzysiej\RyobiCrawler\Models\Product;
final class PromosController extends BaseController
{
public function __invoke(): void
{
$products = Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->with(['currentPrice'])->get();
$this->twig->display('productList.html.twig', ['products' => $products]);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Krzysiej\RyobiCrawler\Models\Product;
final class SearchController extends BaseController
{
public function __invoke(string $search): void
{
$products = Product::with('price')
->orWhere([['name', 'like', "%$search%"]])
->orWhere([['subTitle', 'like', "%$search%"]])->get();
$this->twig->display('productList.html.twig', ['products' => $products ?? [], 'search' => $search]);
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Krzysiej\RyobiCrawler\Models\Product;
final class StarController extends BaseController
{
public function __invoke(int $productId): void
{
Product::find($productId)->toggleStarred()->save();
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
}

View File

@@ -5,10 +5,10 @@ namespace Krzysiej\RyobiCrawler\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* @property integer $skuID
* @property integer $agilityID
* @property string $name
* @property integer $availableQuantity
* @property integer $stock
@@ -29,6 +29,11 @@ class Product extends Model
{
return $this->hasMany(Price::class);
}
public function currentPrice(): HasOne
{
return $this->hasOne(Price::class)->latestOfMany('created_at');
}
public function stock(): HasMany
{
return $this->hasMany(Stock::class);
@@ -40,10 +45,11 @@ class Product extends Model
return $this;
}
protected function categories(): Attribute
public function categories(): Attribute
{
return Attribute::make(
get: fn(string $value) => array_reverse(json_decode($value, 1)),
set: fn(array $value) => json_encode($value),
);
}
}

View File

@@ -3,13 +3,14 @@
{% block content %}
<table class='table table-hover'>
<tr>
<td><img src='{{ product.image }}&width=150' class='img-fluid' alt='{{ product.name }}'/></td>
<td><a href='?product_id={{ product.id }}'>{{ product.name }}</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='border rounded p-1' alt='{{ product.name }}'/></td>
<td><a href='/product/{{ product.id }}' class="text-decoration-none">{{ 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="?category={{ category }}"> {{ category }} </a></li>
<li class="nav-item"><a class="nav-link" href="/category/{{ category }}"> {{ category }} </a></li>
{% endfor %}
</ul>
</td>
@@ -17,7 +18,13 @@
</tr>
<tr>
<td colspan="4">
<div style="width: 800px;">
<canvas id="price"></canvas>
</div>
</td>
</tr>
<tr>
<td colspan="4">
<table class='table table-hover table-sm mb-0'>
<thead>
<tr>
@@ -38,5 +45,46 @@
</td>
</tr>
</table>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
const ctx = document.getElementById('price');
new Chart(ctx, {
type: 'line',
data: {
labels: ['{{ price_dates|raw }}'],
datasets: [{
label: 'Price (PLN)',
data: [{{ price_list }}],
borderWidth: 1
}]
},
options: {
animation: false,
plugins: {
title: {
display: true,
text: 'Price in time'
},
},
scales: {
x: {
title: {
display: true,
text: 'Date'
}
},
y: {
beginAtZero: true,
title: {
display: true,
text: 'Price'
}
}
}
}
});
</script>
{% endblock %}

View File

@@ -2,21 +2,33 @@
{% block content %}
<table class='table table-hover'>
<thead>
<tr>
<th></th>
<th></th>
<th>Name</th>
<th>Code</th>
<th>Categories</th>
<th></th>
<th>Price</th>
</tr>
</thead>
{% for product in products %}
<tr>
<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='?product_id={{ product.id }}'>{{ product.name }}</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 class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='border rounded p-1' alt='{{ product.name }}'/></td>
<td class="align-middle"><a href='/product/{{ product.id }}' class="text-decoration-none">{{ 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="?category={{ category }}"> {{ category }} </a></li>
<li class="nav-item"><a class="nav-link" href="/category/{{ category }}"> {{ category }} </a></li>
{% endfor %}
</ul>
</td>
<td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
<td class="align-middle">{{ product.price.last.price }}</td>
<td class="align-middle">{% if product.price.last.price != product.price.last.productStandardPrice %}<span class="text-decoration-line-through text-warning">{{ product.price.last.productStandardPrice }}</span> <span class="text-success">{{ ((1 - product.price.last.price / product.price.last.productStandardPrice)*100)|number_format(0) }}%</span>{% else %}{% endif %}</td>
</tr>
{% endfor %}
</table>

View File

@@ -9,14 +9,26 @@
crossorigin="anonymous"/>
</head>
<body>
<nav class="navbar sticky-top bg-body-tertiary border-bottom border-secondary border-1">
<nav class="navbar navbar-expand-lg 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>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/promos">Promos</a>
</li>
</ul>
</div>
</div>
<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>
</div>
</nav>
{% block content %}{% endblock %}
</body>