Created
October 26, 2022 02:41
-
-
Save JohnAtl/7c6889bd70331f98977b57422d415f86 to your computer and use it in GitHub Desktop.
business_rule_engine demo
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
params = { | |
'products_in_stock': 10 | |
} | |
def order_more(items_to_order): | |
print('you ordered {} new items'.format(items_to_order)) | |
return items_to_order | |
with open('test.rules', 'r') as f: | |
rules = f.read() | |
from business_rule_engine import RuleParser | |
parser = RuleParser() | |
parser.register_function(order_more) | |
parser.parsestr(rules) | |
parser.execute(params) |
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
rule "order new items" | |
when | |
products_in_stock < 20 | |
then | |
order_more(50) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment