9 Commits

Author SHA1 Message Date
c16ab192ed Add scrape time to footer
All checks were successful
/ deploy-job (push) Successful in 1s
2026-03-04 07:33:10 +01:00
fc89944cf1 Fix badges colors
All checks were successful
/ deploy-job (push) Successful in 0s
2026-03-03 08:47:23 +01:00
a3b36df64e Fix badges colors 2026-03-03 08:47:23 +01:00
ce1fa049d1 Merge pull request 'feature/dark-theme' (#75) from feature/dark-theme into master
All checks were successful
/ deploy-job (push) Successful in 1s
2026-03-01 15:11:23 +01:00
f01398603d Merge branch 'refs/heads/master' into feature/dark-theme
# Conflicts:
#	templates/template.html.twig
2026-03-01 11:35:37 +01:00
8a520b11d6 Add footer with switch. 2026-03-01 10:46:47 +01:00
7eb9d42f97 Trigger action only on push to master
All checks were successful
/ deploy-job (push) Successful in 0s
2026-02-20 08:46:44 +01:00
52c16470e6 Add update script. 2026-02-20 08:46:44 +01:00
ddc4cf9997 Start working on dark theme 2026-01-30 15:51:40 +01:00
10 changed files with 103 additions and 74 deletions

View File

@@ -1,5 +1,7 @@
on:
push:
branches:
- master
workflow_dispatch:
jobs:
deploy-job:

View File

@@ -246,16 +246,6 @@ class Migrate extends Command
$table->json('promotions')->nullable();
});
}
if (!Capsule::schema()->hasColumn('prices', 'conversionRate')) {
Capsule::schema()->table('prices', function (Blueprint $table) {
$table->float('conversionRate')->nullable();
});
}
if (!Capsule::schema()->hasColumn('products', 'conversionRate')) {
Capsule::schema()->table('products', function (Blueprint $table) {
$table->float('conversionRate')->nullable();
});
}
}
public function index(): void

View File

@@ -23,17 +23,15 @@ class ScrapeWebsite extends Command
{
const COUNTRY_ID = 'country';
private Client $client;
private array $rates;
public function __construct(protected Capsule $database)
{
parent::__construct();
$this->client = new Client();
$this->rates = $this->getCurrencyExchange();
}
protected function configure(): void
{
$this->client = new Client();
$this->addOption(self::COUNTRY_ID, 'c', InputOption::VALUE_OPTIONAL, 'Country id');
}
@@ -70,7 +68,6 @@ class ScrapeWebsite extends Command
$product->priceLowest = $product->lowestPrice->price;
$product->lastSeen = $newestPrice->created_at->format('Y-m-d');
$product->stock = $currentStock->stock;
$product->conversionRate = $newestPrice->conversionRate;
$product->save(['timestamps' => false]);
$progress->advance();
}
@@ -79,6 +76,8 @@ class ScrapeWebsite extends Command
$output->writeln('Update prices - DONE');
$output->writeln('COMMAND - DONE');
file_put_contents('templates/lastscrape.html.twig', date('Y-m-d H:i:s'));
return Command::SUCCESS;
}
@@ -101,7 +100,7 @@ class ScrapeWebsite extends Command
$products = array_merge($products, $responseObject->products);
$page++;
$canLoadMore = $responseObject->canLoadMore;
} catch (GuzzleException) {
} catch (GuzzleException $e) {
return $products;
}
} while ($canLoadMore);
@@ -135,7 +134,6 @@ class ScrapeWebsite extends Command
$price->price = $product->productPrice;
$price->productStandardPrice = $product->productStandardPrice;
$price->lowestProductPrice30Days = $product->lowestProductPrice30Days;
$price->conversionRate = $this->getConversionRate($country->currency);
$productModel->price()->save($price);
}
$stockExist = $productModel->stock()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
@@ -151,22 +149,4 @@ class ScrapeWebsite extends Command
$productModel->stock()->save($stock);
}
}
public function getCurrencyExchange(): array
{
$result = $this->client->request('GET', 'https://api.nbp.pl/api/exchangerates/tables/A/?format=json');
$rates = ['PLN' => 1.0];
foreach(json_decode($result->getBody()->getContents(),true)[0]['rates'] as $rate){
$rates[$rate['code']] = $rate['mid'];
}
return $rates;
}
private function getConversionRate(string $currency): float
{
$currency = strtoupper($currency);
return $this->rates[$currency];
}
}

View File

@@ -7,13 +7,9 @@ use Krzysiej\RyobiCrawler\Twig\AppExtension;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Twig\Extra\Cache\CacheExtension;
use Twig\Extra\Cache\CacheRuntime;
use Twig\Extra\TwigExtraBundle\TwigExtraBundle;
class Kernel extends BaseKernel

View File

@@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property float $price
* @property float $productStandardPrice
* @property float $lowestProductPrice30Days
* @property float $conversionRate
*/
class Price extends Model
{

View File

@@ -27,7 +27,6 @@ use function Symfony\Component\Clock\now;
* @property float $priceLowest
* @property float $productStandardPrice
* @property float $lowestProductPrice30Days
* @property float $conversionRate
* @property Date $lastSeen
* @property integer $stock
* @property Object $promotions
@@ -104,11 +103,6 @@ class Product extends Model
);
}
public function conversionRate(): ?float
{
return $this->conversionRate;
}
public function isDiscontinued(): bool
{
return $this->lastSeen < now()->format('Y-m-d');

View File

@@ -0,0 +1,12 @@
<div class="container">
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
<div class="col-md-4 d-flex align-items-center">
<span class="mb-md-0 text-body-secondary">© 2025 Company, Inc</span>
<a class="align-items-center text-decoration-none" data-bs-theme-value="light">☀️ Light</a>
<a class="align-items-center text-decoration-none" data-bs-theme-value="dark">🌕 Dark</a>
</div>
<div class="col-md-4 text-end text-muted">
{{ include('lastscrape.html.twig', ignore_missing: true) }}
</div>
</footer>
</div>

View File

@@ -11,8 +11,7 @@
<td>
<a href='{{ path('app_product', {'productId': product.id}) }}'
class="text-decoration-none">{{ product.name }}</a>
<span class="badge text-bg-light"><a href="{{ path('app_search', {'search': product.subTitle}) }}"
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
<a href="{{ path('app_search', {'search': product.subTitle}) }}"><span class="badge text-bg-secondary">{{ product.subTitle }}</span></a>
{% if product.promotions is not null and product.promotions.hasPromotion %}<a
href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span>
</a>{% endif %}

View File

@@ -48,22 +48,19 @@
class="text-decoration-none">{{ product.name }}</a>
<br>
{% if product.stock > 0 %}
<span class="badge text-bg-light">stock: {{ product.stock }}</span>
<span class="badge text-bg-secondary">stock: {{ product.stock }}</span>
{% else %}
<span class="badge text-bg-warning">out of stock</span>
{% endif %}
{% if product.isDiscontinued() %}
<a href="{{ path('app_discontinued') }}"><span class="badge text-bg-secondary" data-bs-toggle="tooltip"
data-bs-title="Last update: {{ product.lastSeen }}">is discontinued</span></a>
<a href="{{ path('app_discontinued') }}"><span class="badge text-bg-secondary" data-bs-title="Last update: {{ product.lastSeen }}">is discontinued</span></a>
{% endif %}
{% if product.isNew() %}
<a href="{{ path('app_new') }}"><span class="badge text-bg-success">is new</span></a>
{% endif %}
<span class="badge text-bg-light"><a
href="{{ path('app_search', {'search': product.subTitle}) }}"
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
<a href="{{ path('app_search', {'search': product.subTitle}) }}"><span class="badge text-bg-secondary">{{ product.subTitle }}</span></a>
{% if product.promotions is not null and product.promotions.hasPromotion %}<a href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span></a>{% endif %}
<span class="badge text-bg-light">{{ product.country.countryName }}</span>
<span class="badge text-bg-secondary">{{ product.country.countryName }}</span>
</td>
<td class="align-middle">
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
@@ -80,30 +77,19 @@
<td class="align-middle"><a href='https://{{ product.country.locale }}.ryobitools.eu{{ product.url }}'>link</a></td>
<td class="align-middle text-end">
{% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %}
{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}<br>
{% if product.conversionRate is not empty and product.conversionRate != 1 %}
{{ (product.priceLowest * product.conversionRate) | format_currency('PLN', {}, 'pl') }}
{% endif %}
{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}
{% else %}
{% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}{% else %}
<span class="badge text-bg-info">now lowest</span>
{% endif %}</td>
<span class="badge text-bg-info">now lowest</span>{% endif %}</td>
{% endif %}
<td class="align-middle text-end">
{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }}<br>
{% if product.conversionRate is not empty and product.conversionRate != 1 %}
{{ (product.priceCurrent * product.conversionRate) | format_currency('PLN', {}, 'pl') }}
{% endif %}
</td>
<td class="align-middle text-end">{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }}</td>
<td class="align-middle">
<div class="d-flex flex-row">
{% if product.priceCurrent != product.productStandardPrice %}
<span class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</span>
{% if product.conversionRate is not empty and product.conversionRate != 1 %}
<span class="badge text-bg-warning text-decoration-line-through flex-fill">{{ (product.productStandardPrice * product.conversionRate) | format_currency('PLN', {}, 'pl') }}</span>
{% endif %}
<span class="badge text-bg-success flex-fill">{{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%</span>
{% if product.priceCurrent != product.productStandardPrice %}<span
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</span>
<span
class="badge text-bg-success flex-fill">{{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%</span>
{% endif %}
</div>
</td>

View File

@@ -1,6 +1,75 @@
<!doctype html>
<html lang="en" data-bs-theme="light">
<html lang="en" data-bs-theme="">
<head>
<script>
(() => {
'use strict'
const getStoredTheme = () => localStorage.getItem('theme')
const setStoredTheme = theme => localStorage.setItem('theme', theme)
const getPreferredTheme = () => {
const storedTheme = getStoredTheme()
if (storedTheme) {
return storedTheme
}
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}
const setTheme = theme => {
if (theme === 'auto') {
document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'))
} else {
document.documentElement.setAttribute('data-bs-theme', theme)
}
}
setTheme(getPreferredTheme())
const showActiveTheme = (theme, focus = false) => {
const themeSwitcher = document.querySelector('#bd-theme')
if (!themeSwitcher) {
return
}
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
element.classList.remove('active')
})
btnToActive.classList.add('active')
if (focus) {
themeSwitcher.focus()
}
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
const storedTheme = getStoredTheme()
if (storedTheme !== 'light' && storedTheme !== 'dark') {
setTheme(getPreferredTheme())
}
})
window.addEventListener('DOMContentLoaded', () => {
showActiveTheme(getPreferredTheme())
document.querySelectorAll('[data-bs-theme-value]')
.forEach(toggle => {
toggle.addEventListener('click', () => {
const theme = toggle.getAttribute('data-bs-theme-value')
setStoredTheme(theme)
setTheme(theme)
showActiveTheme(theme, true)
})
})
})
})()
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
@@ -13,7 +82,8 @@
<div class="container-fluid">
<a class="navbar-brand" href="{{ path('app_home') }}">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">
<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">
@@ -45,6 +115,7 @@
</nav>
{% block content %}{% endblock %}
{{ include('footer.html.twig') }}
<script src="/templates/js/bootstrap.bundle.min.js"></script>
</body>
</html>