adding ability to set frequency on a DataSourceSet

This commit is contained in:
evilchili 2023-12-24 12:15:48 -08:00
parent e751702610
commit 51d9aa02b4

View File

@ -38,8 +38,15 @@ class DataSourceSet(WeightedSet):
def __init__(self, source: Path):
self.source = DataSource(source.read_text())
self._populate()
def _populate(self):
super().__init__(*[(key, value) for key, value in self.source.frequencies.items()])
def set_frequency(self, frequency: str):
self.source.set_frequency(frequency)
self._populate()
def random(self):
random_key = super().random()
return self.source.as_dict()[random_key]