diff --git a/README.md b/README.md index 529057e..9ec4c8b 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,6 @@ This package has a filter option to filter out potentially inappropriate facts. ```python from randfacts import getFact print(getFact(False)) -``` \ No newline at end of file +``` + +If you want to access the list of facts directly, you can just import the `safeFacts`, `unsafeFacts`, or `allFacts` lists from the randfacts module. \ No newline at end of file diff --git a/randfacts/__init__.py b/randfacts/__init__.py index 60e8067..c128669 100644 --- a/randfacts/__init__.py +++ b/randfacts/__init__.py @@ -1,2 +1,2 @@ from .__version__ import __title__, __description__, __url__, __version__, __author__, __author_email__, __license__, __copyright__ -from randfacts.main import getFact +from randfacts.main import getFact, safeFacts, unsafeFacts, allFacts \ No newline at end of file diff --git a/randfacts/__pycache__/__init__.cpython-39.pyc b/randfacts/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..800d38a Binary files /dev/null and b/randfacts/__pycache__/__init__.cpython-39.pyc differ diff --git a/randfacts/__pycache__/__version__.cpython-39.pyc b/randfacts/__pycache__/__version__.cpython-39.pyc new file mode 100644 index 0000000..5836507 Binary files /dev/null and b/randfacts/__pycache__/__version__.cpython-39.pyc differ diff --git a/randfacts/__pycache__/main.cpython-39.pyc b/randfacts/__pycache__/main.cpython-39.pyc new file mode 100644 index 0000000..f63d379 Binary files /dev/null and b/randfacts/__pycache__/main.cpython-39.pyc differ diff --git a/randfacts/__version__.py b/randfacts/__version__.py index c9ea367..59302c3 100644 --- a/randfacts/__version__.py +++ b/randfacts/__version__.py @@ -1,7 +1,7 @@ __title__ = "randfacts" __description__ = "Package to generate random facts" __url__ = "https://github.com/TabulateJarl8/randfacts" -__version__ = "0.2.11" +__version__ = "0.3.0" __author__ = "Tabulate" __author_email__ = "tabulatejarl8@gmail.com" __license__ = "MIT" diff --git a/randfacts/main.py b/randfacts/main.py index 94b532a..efd37f1 100644 --- a/randfacts/main.py +++ b/randfacts/main.py @@ -1,12 +1,16 @@ -from random import randint +from random import choice import os +dir_path = os.path.dirname(os.path.realpath(__file__)) + +with open(os.path.join(dir_path, "safe.txt")) as f: + safeFacts = [fact.rstrip('\r\n ') for fact in f.readlines() if fact != ''] +with open(os.path.join(dir_path, "unsafe.txt")) as f: + unsafeFacts = [fact.rstrip('\r\n ') for fact in f.readlines() if fact != ''] + +allFacts = safeFacts + unsafeFacts + def getFact(filter=True): - dir_path = os.path.dirname(os.path.realpath(__file__)) - with open(os.path.join(dir_path, "safe.txt")) as f: - safelist = [fact.rstrip('\r\n ') for fact in f.readlines() if fact != ''] - with open(os.path.join(dir_path, "unsafe.txt")) as f: - unsafelist = [fact.rstrip('\r\n ') for fact in f.readlines() if fact != ''] if filter == False: - safelist += unsafelist - return safelist[randint(0, len(safelist) - 1)] + return choice(allFacts) + return choice(safeFacts)