From 49d8004b71f1cf6cecd4927e06fef5799560660b Mon Sep 17 00:00:00 2001 From: Benjamin Sigonneau Date: Wed, 20 Jul 2022 22:35:38 +0200 Subject: [PATCH] Show last 10 prices by default in CLI --- fioul.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) mode change 100644 => 100755 fioul.py diff --git a/fioul.py b/fioul.py old mode 100644 new mode 100755 index bbdc0e4..ff2e26d --- a/fioul.py +++ b/fioul.py @@ -32,6 +32,11 @@ def get_price(): return product["default_price_tax"] +def get_prices(n=10): + query = Price.select().order_by(Price.date.desc()).limit(n) + return query + + def store_current_price(): today = date.today() # Get price returns a float (price per L) @@ -63,14 +68,19 @@ def subcommand(args=[], parent=subparsers): return decorator +def argument(*name_or_flags, **kwargs): + return ([*name_or_flags], kwargs) + + @subcommand() def update(args): store_current_price() -@subcommand() +@subcommand([argument("n", default=42, nargs="?", type=int)]) def show(args): - print(get_price()) + for x in get_prices(args.n): + print(x.date, x.price) @subcommand()