adding support for custom data sources
This commit is contained in:
parent
5c57d262d5
commit
0fd4a69980
|
@ -2,7 +2,7 @@ import yaml
|
||||||
import random
|
import random
|
||||||
from csv2md.table import Table
|
from csv2md.table import Table
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from typing import Optional, List, IO
|
from typing import Optional, List, IO, Union
|
||||||
|
|
||||||
|
|
||||||
class DataSource:
|
class DataSource:
|
||||||
|
@ -90,7 +90,7 @@ class RollTable:
|
||||||
d2-d4 Bar
|
d2-d4 Bar
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, sources: List[str], frequency: str = 'default',
|
def __init__(self, sources: Union[List[str], List[DataSource]], frequency: str = 'default',
|
||||||
die: Optional[int] = 20, hide_rolls: bool = False) -> None:
|
die: Optional[int] = 20, hide_rolls: bool = False) -> None:
|
||||||
self._sources = sources
|
self._sources = sources
|
||||||
self._frequency = frequency
|
self._frequency = frequency
|
||||||
|
@ -214,9 +214,12 @@ class RollTable:
|
||||||
# create the datasource objects
|
# create the datasource objects
|
||||||
self._data = []
|
self._data = []
|
||||||
for src in self._sources:
|
for src in self._sources:
|
||||||
ds = DataSource(src, frequency=self._frequency)
|
if type(src) is str:
|
||||||
ds.load_source()
|
ds = DataSource(src, frequency=self._frequency)
|
||||||
self._data.append(ds)
|
ds.load_source()
|
||||||
|
self._data.append(ds)
|
||||||
|
else:
|
||||||
|
self._data.append(src)
|
||||||
|
|
||||||
# merge the headers
|
# merge the headers
|
||||||
self._headers = []
|
self._headers = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user