Show last 10 prices by default in CLI
This commit is contained in:
14
fioul.py
Normal file → Executable file
14
fioul.py
Normal file → Executable 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()
|
||||||
|
|||||||
Reference in New Issue
Block a user