Add DynamoDb support
This commit is contained in:
27
text_db.py
Normal file
27
text_db.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import random
|
||||
|
||||
import constants
|
||||
from db_service import DbService
|
||||
import common
|
||||
|
||||
|
||||
class TextDb(DbService):
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.FACTS_LIST = None
|
||||
|
||||
def load_facts_from_file(self):
|
||||
facts_file = open(f"{constants.FACTS_PATH}", mode="r")
|
||||
self.FACTS_LIST = facts_file.readlines()
|
||||
assert self.FACTS_LIST
|
||||
|
||||
def get_fact(self):
|
||||
if self.FACTS_LIST is None:
|
||||
self.load_facts_from_file()
|
||||
return random.choice(self.FACTS_LIST)
|
||||
|
||||
def get_multiple_facts(self, count=5):
|
||||
if self.FACTS_LIST is None:
|
||||
self.load_facts_from_file()
|
||||
return random.sample(self.FACTS_LIST, k=count)
|
||||
Reference in New Issue
Block a user