From 4be68a49152b588c35f68f94d94a08d20fa7aa32 Mon Sep 17 00:00:00 2001 From: Florian Brinker Date: Tue, 20 Apr 2021 00:28:43 +0200 Subject: [PATCH] Add example --- README.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 79c70e0..1ee83d4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,40 @@ # cookidoo-shopping-advanced -A Cookidoo Shopping List Scraper and Parser for better results. It can unify and merge all ingredients by different rule sets. \ No newline at end of file +A Cookidoo Shopping List Scraper and Parser for better results. It can unify and merge all ingredients by different rule sets. + +## Example + +```php +// use ... +$config = require('config.php'); + +$cookidooScraper = new CookidooScraper(); +$cookidooScraper->login( + $config['account']['username'], + $config['account']['password'] +); + +$list = $cookidooScraper->getShopptingList(); + +$ruleApplicator = new RuleApplicator(); +$ruleApplicator->applyRules( + $list, + [ + new Rules\Omit(), + new Rules\Simplify(), + new Rules\MergeSame(), + ] +); + +$categorizedList = $list->getByCategory(); +// ... +``` + +## Caching + +You can cache the shopping list as a json file: +```php +file_put_contents('./list.json', $list->toJson()); + +$list = ShoppingList::fromJson(file_get_contents('./list.json')); +``` \ No newline at end of file