Add abstract base classes for sources and outputs.
This commit is contained in:
parent
660b7d709c
commit
a91309678c
7 changed files with 56 additions and 5 deletions
7
src/pricehist/outputs/baseoutput.py
Normal file
7
src/pricehist/outputs/baseoutput.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class BaseOutput(ABC):
|
||||
@abstractmethod
|
||||
def format(self) -> str:
|
||||
pass
|
|
@ -1,7 +1,9 @@
|
|||
from pricehist.format import Format
|
||||
|
||||
from .baseoutput import BaseOutput
|
||||
|
||||
class Beancount:
|
||||
|
||||
class Beancount(BaseOutput):
|
||||
def format(self, series, source=None, fmt=Format()):
|
||||
lines = []
|
||||
for price in series.prices:
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
from pricehist.format import Format
|
||||
|
||||
from .baseoutput import BaseOutput
|
||||
|
||||
class CSV:
|
||||
|
||||
class CSV(BaseOutput):
|
||||
def format(self, series, source=None, fmt=Format()):
|
||||
lines = ["date,base,quote,amount,source,type"]
|
||||
for price in series.prices:
|
||||
|
|
|
@ -5,8 +5,10 @@ from importlib.resources import read_text
|
|||
from pricehist import __version__
|
||||
from pricehist.format import Format
|
||||
|
||||
from .baseoutput import BaseOutput
|
||||
|
||||
class GnuCashSQL:
|
||||
|
||||
class GnuCashSQL(BaseOutput):
|
||||
def format(self, series, source=None, fmt=Format()):
|
||||
src = f"pricehist:{source.id()}"
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
from pricehist.format import Format
|
||||
|
||||
from .baseoutput import BaseOutput
|
||||
|
||||
class Ledger:
|
||||
|
||||
class Ledger(BaseOutput):
|
||||
def format(self, series, source=None, fmt=Format()):
|
||||
lines = []
|
||||
for price in series.prices:
|
||||
|
|
34
src/pricehist/sources/basesource.py
Normal file
34
src/pricehist/sources/basesource.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
from abc import ABC, abstractmethod
|
||||
|
||||
from pricehist.series import Series
|
||||
|
||||
|
||||
class BaseSource(ABC):
|
||||
@abstractmethod
|
||||
def id(self) -> str:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def name(self) -> str:
|
||||
pass
|
||||
|
||||
def description(self) -> str:
|
||||
pass
|
||||
|
||||
def source_url(self) -> str:
|
||||
pass
|
||||
|
||||
def start(self) -> str:
|
||||
pass
|
||||
|
||||
def types(self) -> list[str]:
|
||||
pass
|
||||
|
||||
def notes(self) -> str:
|
||||
pass
|
||||
|
||||
def symbols(self) -> list[str]:
|
||||
pass
|
||||
|
||||
def fetch(self, series: Series) -> Series:
|
||||
pass
|
|
@ -6,8 +6,10 @@ import requests
|
|||
|
||||
from pricehist.price import Price
|
||||
|
||||
from .basesource import BaseSource
|
||||
|
||||
class CoinDesk:
|
||||
|
||||
class CoinDesk(BaseSource):
|
||||
def id(self):
|
||||
return "coindesk"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue