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: