Don't use static methods. Use name by_code instead of bycode.

This commit is contained in:
Chris Berkhout 2021-05-25 15:26:24 +02:00
parent 231be6e62c
commit 03582cf52a
6 changed files with 25 additions and 39 deletions

View file

@ -66,7 +66,7 @@ def cmd_source(args):
if output != "":
print(output)
source = sources.by_id[args.identifier]()
source = sources.by_id[args.identifier]
if args.symbols:
print("\n".join(source.symbols()))
@ -84,8 +84,8 @@ def cmd_source(args):
def cmd_fetch(args):
source = sources.by_id[args.source]()
output = outputs.by_type[args.output]()
source = sources.by_id[args.source]
output = outputs.by_type[args.output]
start = args.start or source.start()
type = args.type or (source.types() + ["unknown"])[0]

View file

@ -18,7 +18,7 @@ Functions:
current_data_date() -> str
historical_data_date() -> str
bycode() -> dict[str, ISOCurrency]
by_code() -> dict[str, ISOCurrency]
"""
@ -50,7 +50,7 @@ def historical_data_date():
return three.cssselect("ISO_4217")[0].attrib["Pblshd"]
def bycode():
def by_code():
result = {}
one = etree.fromstring(read_binary("pricehist.resources", "list_one.xml"))

View file

@ -6,8 +6,8 @@ from .ledger import Ledger
default = "ledger"
by_type = {
"beancount": Beancount,
"csv": CSV,
"gnucash-sql": GnuCashSQL,
"ledger": Ledger,
"beancount": Beancount(),
"csv": CSV(),
"gnucash-sql": GnuCashSQL(),
"ledger": Ledger(),
}

View file

@ -2,4 +2,4 @@ from .coindesk import CoinDesk
from .coinmarketcap import CoinMarketCap
from .ecb import ECB
by_id = {CoinDesk.id(): CoinDesk, CoinMarketCap.id(): CoinMarketCap, ECB.id(): ECB}
by_id = {source.id(): source for source in [CoinDesk(), CoinMarketCap(), ECB()]}

View file

@ -7,35 +7,28 @@ from pricehist.price import Price
class CoinDesk:
@staticmethod
def id():
def id(self):
return "coindesk"
@staticmethod
def name():
def name(self):
return "CoinDesk Bitcoin Price Index"
@staticmethod
def description():
def description(self):
return (
"An average of bitcoin prices across leading global exchanges. \n"
"Powered by CoinDesk, https://www.coindesk.com/price/bitcoin"
)
@staticmethod
def source_url():
def source_url(self):
return "https://www.coindesk.com/coindesk-api"
@staticmethod
def start():
def start(self):
return "2010-07-17"
@staticmethod
def types():
def types(self):
return ["close"]
@staticmethod
def notes():
def notes(self):
return ""
def symbols(self):

View file

@ -9,32 +9,25 @@ from pricehist.price import Price
class ECB:
@staticmethod
def id():
def id(self):
return "ecb"
@staticmethod
def name():
def name(self):
return "European Central Bank"
@staticmethod
def description():
def description(self):
return "European Central Bank Euro foreign exchange reference rates"
@staticmethod
def source_url():
def source_url(self):
return "https://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html"
@staticmethod
def start():
def start(self):
return "1999-01-04"
@staticmethod
def types():
def types(self):
return ["reference"]
@staticmethod
def notes():
def notes(self):
return ""
def symbols(self):
@ -42,7 +35,7 @@ class ECB:
root = etree.fromstring(data)
nodes = root.cssselect("[currency]")
currencies = sorted(set([n.attrib["currency"] for n in nodes]))
iso = isocurrencies.bycode()
iso = isocurrencies.by_code()
pairs = [f"EUR/{c} Euro against {iso[c].name}" for c in currencies]
return pairs