--rename-base, --rename-quote and --rename-time options.
This commit is contained in:
parent
df9d0aeb85
commit
f5e6e01298
5 changed files with 42 additions and 8 deletions
|
@ -44,8 +44,20 @@ def cmd_source(args):
|
|||
def cmd_fetch(args):
|
||||
source = sources.by_id[args.source]()
|
||||
output = outputs.by_type[args.output]()
|
||||
|
||||
prices = source.fetch(args.pair, args.start, args.end)
|
||||
print(output.format(prices), end="")
|
||||
|
||||
if args.renamebase or args.renamequote:
|
||||
prices = [
|
||||
p._replace(
|
||||
base=(args.renamebase or p.base),
|
||||
quote=(args.renamequote or p.quote),
|
||||
)
|
||||
for p in prices
|
||||
]
|
||||
|
||||
time = args.renametime or "00:00:00"
|
||||
print(output.format(prices, time=time), end="")
|
||||
|
||||
|
||||
def build_parser():
|
||||
|
@ -94,7 +106,8 @@ def build_parser():
|
|||
help="fetch prices",
|
||||
usage=(
|
||||
"pricehist fetch SOURCE PAIR "
|
||||
"[-h] (-s DATE | -sx DATE) [-e DATE] [-o FMT]"
|
||||
"[-h] (-s DATE | -sx DATE) [-e DATE] [-o FMT] "
|
||||
"[--rename-base SYM] [--rename-quote SYM] [--rename-time TIME]"
|
||||
),
|
||||
)
|
||||
fetch_parser.add_argument(
|
||||
|
@ -146,5 +159,26 @@ def build_parser():
|
|||
default=outputs.default,
|
||||
help=f"output format (default: {outputs.default})",
|
||||
)
|
||||
fetch_parser.add_argument(
|
||||
"--rename-base",
|
||||
dest="renamebase",
|
||||
metavar="SYM",
|
||||
type=str,
|
||||
help="rename base symbol",
|
||||
)
|
||||
fetch_parser.add_argument(
|
||||
"--rename-quote",
|
||||
dest="renamequote",
|
||||
metavar="SYM",
|
||||
type=str,
|
||||
help="rename quote symbol",
|
||||
)
|
||||
fetch_parser.add_argument(
|
||||
"--rename-time",
|
||||
dest="renametime",
|
||||
metavar="TIME",
|
||||
type=str,
|
||||
help="set a particular time of day, e.g. 23:59:59",
|
||||
)
|
||||
|
||||
return parser
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Beancount:
|
||||
def format(self, prices):
|
||||
def format(self, prices, time=None):
|
||||
lines = []
|
||||
for price in prices:
|
||||
lines.append(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class CSV:
|
||||
def format(self, prices):
|
||||
def format(self, prices, time=None):
|
||||
lines = ["date,base,quote,amount"]
|
||||
for price in prices:
|
||||
line = ",".join([price.date, price.base, price.quote, str(price.amount)])
|
||||
|
|
|
@ -6,13 +6,13 @@ from pricehist import __version__
|
|||
|
||||
|
||||
class GnuCashSQL:
|
||||
def format(self, prices):
|
||||
def format(self, prices, time=None):
|
||||
source = "pricehist"
|
||||
typ = "unknown"
|
||||
|
||||
values_parts = []
|
||||
for price in prices:
|
||||
date = f"{price.date} 00:00:00"
|
||||
date = f"{price.date} {time}"
|
||||
m = hashlib.sha256()
|
||||
m.update(
|
||||
"".join(
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
class Ledger:
|
||||
def format(self, prices):
|
||||
def format(self, prices, time=None):
|
||||
lines = []
|
||||
for price in prices:
|
||||
date = str(price.date).translate(str.maketrans("-", "/"))
|
||||
lines.append(f"P {date} 00:00:00 {price.base} {price.amount} {price.quote}")
|
||||
lines.append(f"P {date} {time} {price.base} {price.amount} {price.quote}")
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
# TODO support additional details of the format:
|
||||
|
|
Loading…
Add table
Reference in a new issue