Compare commits
10 Commits
feature/ta
...
feature/fl
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fbd555bb3 | |||
| de4915972c | |||
| 9c2405dd3f | |||
| da6a8f86c2 | |||
| 2c40fb0e61 | |||
| 5314a6a70a | |||
|
|
f772532309 | ||
|
|
17159e811f | ||
|
|
76d8b7d9cf | ||
|
|
f30304cbe9 |
2
bin/cachewarmup
Executable file
2
bin/cachewarmup
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
bin/cli php console.php app:cache:warm-twig
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
[ -z "$1" ] && echo "Please specify a Composer command (ex. install)" && exit
|
[ -z "$1" ] && bin/cli composer list && exit
|
||||||
bin/cli composer "$@"
|
bin/cli composer "$@"
|
||||||
1151
composer.lock
generated
1151
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
|
|
||||||
#[AsCommand(name: 'app:cache:warm-twig', description: '')]
|
#[AsCommand(name: 'app:cache:warm-twig', description: 'Warmup twig cache')]
|
||||||
class CacheWarmCommand extends Command
|
class CacheWarmCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|||||||
@@ -21,15 +21,13 @@ class ScrapeWebsite extends Command
|
|||||||
{
|
{
|
||||||
private Client $client;
|
private Client $client;
|
||||||
|
|
||||||
|
public function __construct(protected Capsule $database)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$capsule = new Capsule;
|
|
||||||
$capsule->addConnection([
|
|
||||||
'driver' => 'sqlite',
|
|
||||||
'database' => __DIR__ . '/../../database.sqlite',
|
|
||||||
]);
|
|
||||||
$capsule->setAsGlobal();
|
|
||||||
$capsule->bootEloquent();
|
|
||||||
$this->client = new Client();
|
$this->client = new Client();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,7 @@ class BaseController extends AbstractController
|
|||||||
{
|
{
|
||||||
protected Environment $twig;
|
protected Environment $twig;
|
||||||
|
|
||||||
public function __construct(protected FilesystemAdapter $cache)
|
public function __construct(protected FilesystemAdapter $cache, protected Capsule $database)
|
||||||
{
|
{
|
||||||
$capsule = new Capsule;
|
|
||||||
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/../../database.sqlite']);
|
|
||||||
$capsule->setAsGlobal();
|
|
||||||
$capsule->bootEloquent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ final class SearchController extends BaseController
|
|||||||
->orWhere([['name', 'like', "%$search%"]])
|
->orWhere([['name', 'like', "%$search%"]])
|
||||||
->orWhere([['subTitle', 'like', "%$search%"]])->get();
|
->orWhere([['subTitle', 'like', "%$search%"]])->get();
|
||||||
|
|
||||||
return $this->render('productList.html.twig', ['products' => $products ?? [], 'search' => $search]);
|
return $this->render('productList.html.twig', ['products' => $products ?? [], 'search' => $search, 'listType' => 'search_'.$search]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/DatabaseFactory.php
Normal file
14
src/DatabaseFactory.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler;
|
||||||
|
|
||||||
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
class DatabaseFactory
|
||||||
|
{
|
||||||
|
public static function create(Capsule $capsule): void
|
||||||
|
{
|
||||||
|
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/../database.sqlite']);
|
||||||
|
$capsule->setAsGlobal();
|
||||||
|
$capsule->bootEloquent();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Krzysiej\RyobiCrawler;
|
namespace Krzysiej\RyobiCrawler;
|
||||||
|
|
||||||
|
use Illuminate\Database\Capsule\Manager;
|
||||||
use Krzysiej\RyobiCrawler\Twig\AppExtension;
|
use Krzysiej\RyobiCrawler\Twig\AppExtension;
|
||||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||||
@@ -34,8 +35,9 @@ class Kernel extends BaseKernel
|
|||||||
'secret' => 'S0ME_SECRET'
|
'secret' => 'S0ME_SECRET'
|
||||||
]);
|
]);
|
||||||
$services = $container->services()->defaults()->autowire()->autoconfigure();
|
$services = $container->services()->defaults()->autowire()->autoconfigure();
|
||||||
|
$services->set(Manager::class)->configurator([DatabaseFactory::class, 'create']);
|
||||||
$services->load('Krzysiej\\RyobiCrawler\\', __DIR__ )
|
$services->load('Krzysiej\\RyobiCrawler\\', __DIR__ )
|
||||||
->exclude('../src/{Models,Twig,Kernel.php}');
|
->exclude('../src/{Models,Twig,DatabaseFactory.php,Kernel.php}');
|
||||||
$services->set('twig.extension.cache', AppExtension::class)->tag('twig.extension');
|
$services->set('twig.extension.cache', AppExtension::class)->tag('twig.extension');
|
||||||
$services->set(CacheExtension::class)->tag('twig.extension');
|
$services->set(CacheExtension::class)->tag('twig.extension');
|
||||||
$services->set(FilesystemAdapter::class)->args([
|
$services->set(FilesystemAdapter::class)->args([
|
||||||
|
|||||||
@@ -3,21 +3,22 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
{% cache 'list_' ~ listType %}
|
{% cache 'list_' ~ listType %}
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class='table table-hover'>
|
{# <table class='table table-hover'>#}
|
||||||
<thead>
|
{# <thead>#}
|
||||||
<tr>
|
{# <tr>#}
|
||||||
<th></th>
|
{# <th></th>#}
|
||||||
<th></th>
|
{# <th></th>#}
|
||||||
<th>Name</th>
|
{# <th>Name</th>#}
|
||||||
<th>Categories</th>
|
{# <th>Categories</th>#}
|
||||||
<th></th>
|
{# <th></th>#}
|
||||||
<th class="text-end">Lowest Price</th>
|
{# <th class="text-end">Lowest Price</th>#}
|
||||||
<th class="text-end">Current Price</th>
|
{# <th class="text-end">Current Price</th>#}
|
||||||
<th></th>
|
{# <th></th>#}
|
||||||
</tr>
|
{# </tr>#}
|
||||||
</thead>
|
{# </thead>#}
|
||||||
{% for product in products %}
|
{% for product in products %}
|
||||||
<tr>
|
<div class="d-inline-flex">
|
||||||
|
|
||||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
||||||
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred == true %}★{% else %} ☆ {% endif %}</a></td>
|
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred == true %}★{% else %} ☆ {% endif %}</a></td>
|
||||||
<td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='img-thumbnail' alt='{{ product.name }}'/></td>
|
<td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='img-thumbnail' alt='{{ product.name }}'/></td>
|
||||||
@@ -38,7 +39,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb mb-0">
|
||||||
{% for category in product.categories %}
|
{% for category in product.categories %}
|
||||||
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none" href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none" href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -51,14 +52,14 @@
|
|||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<div class="d-flex flex-row">
|
<div class="d-flex flex-row">
|
||||||
{% if product.price.last.price != product.price.last.productStandardPrice %}<span
|
{% if product.price.last.price != product.price.last.productStandardPrice %}<span
|
||||||
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.price.last.productStandardPrice | format_currency('PLN', {}, 'pl') }}</span> <span
|
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.price.last.productStandardPrice | format_currency('PLN', {}, 'pl') }}</span> <span
|
||||||
class="badge text-bg-success flex-fill">{{ ((1 - product.price.last.price / product.price.last.productStandardPrice)*100)|number_format(0) }}%</span>
|
class="badge text-bg-success flex-fill">{{ ((1 - product.price.last.price / product.price.last.productStandardPrice)*100)|number_format(0) }}%</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
{# </table>#}
|
||||||
</div>
|
</div>
|
||||||
{% endcache %}
|
{% endcache %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user