From 12f40fc30ffa0aab98fb0c99196967ba3d607d53 Mon Sep 17 00:00:00 2001 From: kdh8219 Date: Fri, 22 Dec 2023 22:07:45 +0900 Subject: [PATCH] =?UTF-8?q?fix(choose=5Fsentence):=20=EB=AF=B8=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EB=90=9C=20=EC=BD=94=EB=93=9C=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/choose_sentence.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/choose_sentence.py b/src/choose_sentence.py index 93a0bd3..82e10e7 100644 --- a/src/choose_sentence.py +++ b/src/choose_sentence.py @@ -8,25 +8,20 @@ from dotenv import load_dotenv load_dotenv() _sentences=[] -# try: -sentence_files=[] -if os.environ.get("SENTENCES_FILE") and os.path.isfile(os.environ["SENTENCES_FILE"]): - sentence_files.append(os.environ["SENTENCE_FILES"]) - -if os.environ.get("SENTENCES_DIRECTORY") and os.path.isdir(os.environ["SENTENCES_DIRECTORY"]): - sentence_files.extend(glob(f'{os.environ["SENTENCES_DIRECTORY"]}*.txt')) - # for (dirpath, dirnames, filenames) in os.walk(os.environ["SENTENCES_DIRECTORY"]): - # for filename in filenames: - # sentence_files.append(filename) +try: + sentence_files=[] + if os.environ.get("SENTENCES_FILE") and os.path.isfile(os.environ["SENTENCES_FILE"]): + sentence_files.append(os.environ["SENTENCE_FILES"]) + + if os.environ.get("SENTENCES_DIRECTORY") and os.path.isdir(os.environ["SENTENCES_DIRECTORY"]): + sentence_files.extend(glob(f'{os.environ["SENTENCES_DIRECTORY"]}*.txt')) -print(sentence_files) - -for sentence_file in sentence_files: - with open(sentence_file, "r") as f: - _sentences.extend(f.readlines()) -# except: -# e = sys.exc_info()[1] -# _sentences = [f"에러발생(진짜임): {e}"] + for sentence_file in sentence_files: + with open(sentence_file, "r") as f: + _sentences.extend(f.readlines()) +except: + e = sys.exc_info()[1] + _sentences = [f"에러발생(진짜임): {e}"] # choose random sentence in google spread sheet def chooseSentence() -> str: