Show last 10 prices by default in CLI

This commit is contained in:
2022-07-20 22:35:38 +02:00
parent b190eebe46
commit 49d8004b71

14
fioul.py Normal file → Executable file
View File

@@ -32,6 +32,11 @@ def get_price():
return product["default_price_tax"] 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(): def store_current_price():
today = date.today() today = date.today()
# Get price returns a float (price per L) # Get price returns a float (price per L)
@@ -63,14 +68,19 @@ def subcommand(args=[], parent=subparsers):
return decorator return decorator
def argument(*name_or_flags, **kwargs):
return ([*name_or_flags], kwargs)
@subcommand() @subcommand()
def update(args): def update(args):
store_current_price() store_current_price()
@subcommand() @subcommand([argument("n", default=42, nargs="?", type=int)])
def show(args): def show(args):
print(get_price()) for x in get_prices(args.n):
print(x.date, x.price)
@subcommand() @subcommand()