-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a1b8e3e
Showing
33 changed files
with
5,101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# In all environments, the following files are loaded if they exist, | ||
# the latter taking precedence over the former: | ||
# | ||
# * .env contains default values for the environment variables needed by the app | ||
# * .env.local uncommitted file with local overrides | ||
# * .env.$APP_ENV committed environment-specific defaults | ||
# * .env.$APP_ENV.local uncommitted environment-specific overrides | ||
# | ||
# Real environment variables win over .env files. | ||
# | ||
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES. | ||
# | ||
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2). | ||
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration | ||
|
||
###> symfony/framework-bundle ### | ||
APP_ENV=dev | ||
APP_SECRET=abaa4ccd47daeb2beffab051df21e71e | ||
###< symfony/framework-bundle ### | ||
|
||
###> symfony/mailer ### | ||
MAILER_DSN=null://null | ||
MAILER_FROM=[email protected] | ||
###< symfony/mailer ### | ||
|
||
MAILER_TO=[email protected] | ||
PHONE_NUMBER=+33 | ||
|
||
###> symfony/twilio-notifier ### | ||
# TWILIO_DSN=twilio://SID:TOKEN@default?from=FROM | ||
###< symfony/twilio-notifier ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
###> symfony/framework-bundle ### | ||
/.env.local | ||
/.env.local.php | ||
/.env.*.local | ||
/config/secrets/prod/prod.decrypt.private.php | ||
/public/bundles/ | ||
/var/ | ||
/vendor/ | ||
###< symfony/framework-bundle ### | ||
|
||
###> friendsofphp/php-cs-fixer ### | ||
/.php_cs | ||
/.php_cs.cache | ||
###< friendsofphp/php-cs-fixer ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__) | ||
->exclude('config') | ||
->exclude('public') | ||
->exclude('var') | ||
->notPath('src/Kernel.php') | ||
; | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@PhpCsFixer' => true, | ||
'@PhpCsFixer:risky' => true, | ||
'@PHP80Migration' => true, | ||
'@PHP80Migration:risky' => true, | ||
'@DoctrineAnnotation' => true, | ||
'concat_space' => ['spacing' => 'one'], | ||
'declare_strict_types' => true, | ||
'mb_str_functions' => true, | ||
'native_function_invocation' => [], | ||
'ordered_class_elements' => ['order' => ['use_trait']], | ||
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], | ||
'php_unit_internal_class' => false, | ||
'php_unit_test_class_requires_covers' => false, | ||
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], | ||
]) | ||
->setFinder($finder) | ||
->setCacheFile(__DIR__.'/var/.php_cs.cache') | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Steven DUBOIS | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# SymPriceAlert | ||
Save money :) Products, services... No limit. | ||
|
||
Be notified when the desired price is reached. | ||
|
||
Made in France. | ||
|
||
## Requirements and installation | ||
You need PHP 8.0 (or higher) and some [extensions enabled](https://symfony.com/doc/5.2/setup.html#technical-requirements) and composer. | ||
```sh | ||
git clone [email protected]:duboiss/SymPriceAlert.git | ||
cd SymPriceAlert | ||
|
||
composer install | ||
``` | ||
|
||
Fill the following environement variables in a new .env.local file. | ||
You need a Twilio account unless you want to use another provider or not receive SMS. | ||
|
||
```env | ||
MAILER_DSN= | ||
MAILER_FROM= | ||
MAILER_TO= | ||
TWILIO_DSN= | ||
PHONE_NUMBER=+33600000000 | ||
``` | ||
|
||
## Configuration | ||
Each website you want to follow need a file in `src/DataProducts` folder. | ||
Two keys are expected: | ||
* selector: a DomCrawler selector | ||
* products: an array of products | ||
|
||
For each product, three keys are expected: | ||
* title: the name of the product or service to analyze (displayed in the logs) | ||
* url: the page to analyze | ||
* desiredPrice: the price at which you wish to be notified (in euros, without spaces and commas) | ||
|
||
A fourth is automatically created if you are notified, **alertedPrice**. | ||
|
||
## Usage | ||
An unique command: `bin/console app:prices:check`. | ||
|
||
A common use case is to run this command with a CRON, once a day for example. | ||
|
||
It parses all urls, analyzes the price (if displayed) and compares it to the desired price. | ||
If the price is equal or lower than the desired price, three options: | ||
1) The user has already been notified for this new price, nothing happens. | ||
2) The user is notified once for this new price. | ||
3) The user has already been notified for this price drop but this one is even more important, he is notified. | ||
|
||
## Exemple with Amazon | ||
Just create a **amazon.json** file with the following structure and it's done. | ||
```sh | ||
# src/DataProducts/amazon.json | ||
{ | ||
"selector": "#priceblock_ourprice", | ||
"products": [ | ||
{ | ||
"title": "Echo dot 4 Alexa", | ||
"url": "https://www.amazon.fr/nouvel-echo-dot-4e-generation-enceinte-connectee-avec-alexa-anthracite/dp/B084DWG2VQ/", | ||
"desiredPrice": 35 | ||
}, | ||
{ | ||
"title": "Xbox Series S", | ||
"url": "https://www.amazon.fr/Xbox-Console-Next-Gen-compacte-digitale/dp/B087VM5XC6/", | ||
"desiredPrice": 220 | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## How it works | ||
SymPriceAlert uses mainly [HTTP Client](https://symfony.com/doc/current/http_client.html), [DomCrawler](https://symfony.com/doc/5.2/components/dom_crawler.html) and [Notifier](https://symfony.com/doc/5.2/notifier.html) components. | ||
|
||
A request is made on the page to be analyzed to retrieve the current price. | ||
|
||
A comparison is then made with the desired price. If necessary, a notification is sent to the user to warn him of this price drop. | ||
|
||
A sleep is performed between each request to avoid the effects of rate limiting (captcha etc). | ||
|
||
### Notifications | ||
By default an email and a SMS are sent but you can easily change this. The channels are adjustable in `config/packages/notifier.yaml`. | ||
|
||
Look at the [documentation](https://symfony.com/doc/5.2/notifier.html) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use App\Kernel; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Input\ArgvInput; | ||
use Symfony\Component\Dotenv\Dotenv; | ||
use Symfony\Component\ErrorHandler\Debug; | ||
|
||
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { | ||
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; | ||
} | ||
|
||
set_time_limit(0); | ||
|
||
require dirname(__DIR__).'/vendor/autoload.php'; | ||
|
||
if (!class_exists(Application::class) || !class_exists(Dotenv::class)) { | ||
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.'); | ||
} | ||
|
||
$input = new ArgvInput(); | ||
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) { | ||
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); | ||
} | ||
|
||
if ($input->hasParameterOption('--no-debug', true)) { | ||
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); | ||
} | ||
|
||
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env'); | ||
|
||
if ($_SERVER['APP_DEBUG']) { | ||
umask(0000); | ||
|
||
if (class_exists(Debug::class)) { | ||
Debug::enable(); | ||
} | ||
} | ||
|
||
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); | ||
$application = new Application($kernel); | ||
$application->run($input); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"name": "duboiss/sympricealert", | ||
"description": "An open-source price alerter based on Symfony.", | ||
"type": "project", | ||
"license": "proprietary", | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require": { | ||
"php": ">=8.0", | ||
"ext-ctype": "*", | ||
"ext-iconv": "*", | ||
"ext-json": "*", | ||
"symfony/console": "5.2.*", | ||
"symfony/css-selector": "5.2.*", | ||
"symfony/dom-crawler": "5.2.*", | ||
"symfony/dotenv": "5.2.*", | ||
"symfony/finder": "5.2.*", | ||
"symfony/flex": "^1.3.1", | ||
"symfony/framework-bundle": "5.2.*", | ||
"symfony/http-client": "5.2.*", | ||
"symfony/mailer": "5.2.*", | ||
"symfony/monolog-bundle": "^3.6", | ||
"symfony/notifier": "5.2.*", | ||
"symfony/twilio-notifier": "5.2.*", | ||
"symfony/yaml": "5.2.*" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^2.18" | ||
}, | ||
"config": { | ||
"optimize-autoloader": true, | ||
"platform": { | ||
"php": "8.0.0" | ||
}, | ||
"preferred-install": { | ||
"*": "dist" | ||
}, | ||
"sort-packages": true | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"App\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"App\\Tests\\": "tests/" | ||
} | ||
}, | ||
"replace": { | ||
"symfony/polyfill-ctype": "*", | ||
"symfony/polyfill-iconv": "*", | ||
"symfony/polyfill-php72": "*" | ||
}, | ||
"scripts": { | ||
"auto-scripts": { | ||
"cache:clear": "symfony-cmd" | ||
}, | ||
"post-install-cmd": [ | ||
"@auto-scripts" | ||
], | ||
"post-update-cmd": [ | ||
"@auto-scripts" | ||
] | ||
}, | ||
"conflict": { | ||
"symfony/symfony": "*" | ||
}, | ||
"extra": { | ||
"symfony": { | ||
"allow-contrib": false, | ||
"require": "5.2.*" | ||
} | ||
} | ||
} |
Oops, something went wrong.