15 Commits

Author SHA1 Message Date
e02fa4fc67 Display prices in PLN
All checks were successful
/ deploy-job (push) Successful in 1s
2026-02-27 11:37:23 +01:00
5088f6173f Add conversion rate to products, prices, and save them while scraping.
All checks were successful
/ deploy-job (push) Successful in 1s
2026-02-26 09:15:02 +01:00
09825de7b9 Add a source of currency exchange rates to scrape command.
All checks were successful
/ deploy-job (push) Successful in 1s
2026-02-25 09:10:14 +01:00
ad0ef20fc2 Country badge.
All checks were successful
/ deploy-job (push) Successful in 1s
2026-02-19 09:33:56 +01:00
e68389bccc Add locale badges to promos 2026-02-19 09:33:56 +01:00
e1dbdc539b Badges as links 2026-02-19 09:33:56 +01:00
f0f26ad64d Badges as links 2026-02-19 09:33:56 +01:00
c6c11d5f7f Merge pull request 'Add the rest of available countries.' (#48) from feature/new-countries into master
All checks were successful
/ deploy-job (push) Successful in 0s
2026-02-17 09:34:55 +01:00
7373657d78 Merge branch 'refs/heads/master' into feature/new-countries
All checks were successful
/ deploy-job (push) Successful in 0s
# Conflicts:
#	src/Command/Migrate.php
#	templates/product.html.twig
#	templates/productList.html.twig
2026-02-17 09:32:38 +01:00
3431c0c131 Add update script.
All checks were successful
/ deploy-job (push) Successful in 1s
2026-02-09 21:29:52 +01:00
a2109a601b Add update script.
All checks were successful
/ deploy-job (push) Successful in 0s
2026-02-09 21:27:33 +01:00
fc63580305 Add update script.
All checks were successful
/ deploy-job (push) Successful in 0s
2026-02-09 21:26:55 +01:00
695da689ac Add update script. 2026-02-09 21:26:40 +01:00
3bbf82f897 Start working on handling multiple countries at once 2026-01-19 08:40:01 +01:00
a388b53cff Add the rest of available countries. 2026-01-19 08:33:19 +01:00
7 changed files with 144 additions and 19 deletions

View File

@@ -1,7 +1,5 @@
on: on:
push: push:
branches:
- master
workflow_dispatch: workflow_dispatch:
jobs: jobs:
deploy-job: deploy-job:
@@ -11,3 +9,7 @@ jobs:
run: echo "test" run: echo "test"
- name: get page - name: get page
run: curl http://192.168.0.129:9001/update run: curl http://192.168.0.129:9001/update
- run: pwd
- run: cd ../ && pwd
- run: pwd
- run: cd /var/www/html/ryobi-crawler && bin/update

View File

@@ -118,6 +118,66 @@ class Migrate extends Command
] ]
); );
} }
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Netherlands')->exists()) {
Capsule::table('countries')->insert([
'countryName' => 'Netherlands',
'productsUrl' => 'https://nl.ryobitools.eu/api/product-listing/get-products',
'cultureCode' => 'nl-NL',
'currency' => 'EUR',
'locale' => 'nl',
'created_at' => now(),
'updated_at' => now(),
]
);
}
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'France')->exists()) {
Capsule::table('countries')->insert([
'countryName' => 'France',
'productsUrl' => 'https://fr.ryobitools.eu/api/product-listing/get-products',
'cultureCode' => 'fr-FR',
'currency' => 'EUR',
'locale' => 'fr',
'created_at' => now(),
'updated_at' => now(),
]
);
}
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Spain')->exists()) {
Capsule::table('countries')->insert([
'countryName' => 'Spain',
'productsUrl' => 'https://es.ryobitools.eu/api/product-listing/get-products',
'cultureCode' => 'es-ES',
'currency' => 'EUR',
'locale' => 'es',
'created_at' => now(),
'updated_at' => now(),
]
);
}
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Poland')->exists()) {
$id = Capsule::table('countries')->insertGetId(
[
'countryName' => 'Poland',
'productsUrl' => 'https://pl.ryobitools.eu/api/product-listing/get-products',
'cultureCode' => 'pl-PL',
'currency' => 'PLN',
'locale' => 'pl',
'created_at' => now(),
'updated_at' => now(),
]);
}
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'UK')->exists()) {
Capsule::table('countries')->insert([
'countryName' => 'UK',
'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products',
'cultureCode' => 'en-GB',
'currency' => 'GBP',
'locale' => 'uk',
'created_at' => now(),
'updated_at' => now(),
]
);
}
if (!Capsule::schema()->hasColumn('products', 'country_id')) { if (!Capsule::schema()->hasColumn('products', 'country_id')) {
Capsule::schema()->table('products', function (Blueprint $table) use ($id) { Capsule::schema()->table('products', function (Blueprint $table) use ($id) {
@@ -186,6 +246,16 @@ class Migrate extends Command
$table->json('promotions')->nullable(); $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 public function index(): void

View File

@@ -23,15 +23,17 @@ class ScrapeWebsite extends Command
{ {
const COUNTRY_ID = 'country'; const COUNTRY_ID = 'country';
private Client $client; private Client $client;
private array $rates;
public function __construct(protected Capsule $database) public function __construct(protected Capsule $database)
{ {
parent::__construct(); parent::__construct();
$this->client = new Client();
$this->rates = $this->getCurrencyExchange();
} }
protected function configure(): void protected function configure(): void
{ {
$this->client = new Client();
$this->addOption(self::COUNTRY_ID, 'c', InputOption::VALUE_OPTIONAL, 'Country id'); $this->addOption(self::COUNTRY_ID, 'c', InputOption::VALUE_OPTIONAL, 'Country id');
} }
@@ -68,6 +70,7 @@ class ScrapeWebsite extends Command
$product->priceLowest = $product->lowestPrice->price; $product->priceLowest = $product->lowestPrice->price;
$product->lastSeen = $newestPrice->created_at->format('Y-m-d'); $product->lastSeen = $newestPrice->created_at->format('Y-m-d');
$product->stock = $currentStock->stock; $product->stock = $currentStock->stock;
$product->conversionRate = $newestPrice->conversionRate;
$product->save(['timestamps' => false]); $product->save(['timestamps' => false]);
$progress->advance(); $progress->advance();
} }
@@ -98,7 +101,7 @@ class ScrapeWebsite extends Command
$products = array_merge($products, $responseObject->products); $products = array_merge($products, $responseObject->products);
$page++; $page++;
$canLoadMore = $responseObject->canLoadMore; $canLoadMore = $responseObject->canLoadMore;
} catch (GuzzleException $e) { } catch (GuzzleException) {
return $products; return $products;
} }
} while ($canLoadMore); } while ($canLoadMore);
@@ -132,6 +135,7 @@ class ScrapeWebsite extends Command
$price->price = $product->productPrice; $price->price = $product->productPrice;
$price->productStandardPrice = $product->productStandardPrice; $price->productStandardPrice = $product->productStandardPrice;
$price->lowestProductPrice30Days = $product->lowestProductPrice30Days; $price->lowestProductPrice30Days = $product->lowestProductPrice30Days;
$price->conversionRate = $this->getConversionRate($country->currency);
$productModel->price()->save($price); $productModel->price()->save($price);
} }
$stockExist = $productModel->stock()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists(); $stockExist = $productModel->stock()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
@@ -147,4 +151,22 @@ class ScrapeWebsite extends Command
$productModel->stock()->save($stock); $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

@@ -20,8 +20,11 @@ final class PromosController extends BaseController
$promos = Product::select($this->database->getConnection()->raw("distinct json_extract(promotions, '$.slug') as slug, json_extract(promotions, '$.tag') as tag")) $promos = Product::select($this->database->getConnection()->raw("distinct json_extract(promotions, '$.slug') as slug, json_extract(promotions, '$.tag') as tag"))
->addSelect('countries.locale')
->whereRaw("json_extract(promotions, '$.tag') is not null") ->whereRaw("json_extract(promotions, '$.tag') is not null")
->get(); ->join('countries', 'products.country_id', '=', 'countries.id')
->get()
->groupBy('locale');
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos' . $promo, 'promos' => $promos->toArray()]); return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos' . $promo, 'promos' => $promos->toArray()]);
} }

View File

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

View File

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

View File

@@ -6,9 +6,17 @@
{% endif %} {% endif %}
{% if listType starts with 'promos' %} {% if listType starts with 'promos' %}
{% for promo in promos %} <ul class="list-group list-group-flush">
<a href="{{ path('app_promos', {'promo': promo.slug}) }}"><span class="badge bg-info">PROMO: {{ promo.tag }}</span></a> {% for locale, promoByLocale in promos %}
{% endfor %} <li class="list-group-item">
<h5 class="d-inline-block"><span class="badge bg-info">{{ locale | upper }}</span></h5>
{% for promo in promoByLocale %}
<a href="{{ path('app_promos', {'promo': promo.slug}) }}"><span
class="badge bg-info">PROMO: {{ promo.tag }} [{{ promo.locale | upper }}]</span></a>
{% endfor %}
</li>
{% endfor %}
</ul>
{% endif %} {% endif %}
@@ -38,22 +46,24 @@
<td class="align-middle"> <td class="align-middle">
<a href='{{ path('app_product', {'productId': product.id}) }}' <a href='{{ path('app_product', {'productId': product.id}) }}'
class="text-decoration-none">{{ product.name }}</a> class="text-decoration-none">{{ product.name }}</a>
<br>
{% if product.stock > 0 %} {% if product.stock > 0 %}
<span class="badge text-bg-light">stock: {{ product.stock }}</span> <span class="badge text-bg-light">stock: {{ product.stock }}</span>
{% else %} {% else %}
<span class="badge text-bg-warning">out of stock</span> <span class="badge text-bg-warning">out of stock</span>
{% endif %} {% endif %}
{% if product.isDiscontinued() %} {% if product.isDiscontinued() %}
<span class="badge text-bg-secondary" data-bs-toggle="tooltip" <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> data-bs-title="Last update: {{ product.lastSeen }}">is discontinued</span></a>
{% endif %} {% endif %}
{% if product.isNew() %} {% if product.isNew() %}
<span class="badge text-bg-success">is new</span> <a href="{{ path('app_new') }}"><span class="badge text-bg-success">is new</span></a>
{% endif %} {% endif %}
<span class="badge text-bg-light"><a <span class="badge text-bg-light"><a
href="{{ path('app_search', {'search': product.subTitle}) }}" href="{{ path('app_search', {'search': product.subTitle}) }}"
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span> class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
{% 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 %} {% 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>
</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: '>';">
@@ -70,19 +80,30 @@
<td class="align-middle"><a href='https://{{ product.country.locale }}.ryobitools.eu{{ product.url }}'>link</a></td> <td class="align-middle"><a href='https://{{ product.country.locale }}.ryobitools.eu{{ product.url }}'>link</a></td>
<td class="align-middle text-end"> <td class="align-middle text-end">
{% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %} {% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %}
{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }} {{ 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 %}
{% else %} {% else %}
{% if product.priceLowest != product.priceCurrent %}{{ 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 %} {% endif %}
<td class="align-middle text-end">{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }}</td> <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"> <td class="align-middle">
<div class="d-flex flex-row"> <div class="d-flex flex-row">
{% if product.priceCurrent != product.productStandardPrice %}<span {% if product.priceCurrent != product.productStandardPrice %}
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-warning text-decoration-line-through flex-fill">{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</span>
<span {% if product.conversionRate is not empty and product.conversionRate != 1 %}
class="badge text-bg-success flex-fill">{{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%</span> <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>
{% endif %} {% endif %}
</div> </div>
</td> </td>