diff --git a/.example.env b/.example.env index f12b746..5b6f7c2 100644 --- a/.example.env +++ b/.example.env @@ -1,4 +1,5 @@ MISSKEY_INSTANCE_ADDRESS="worldc.one" MISSKEY_ACCESS_TOKEN="BWbGlK6lWuUgXQpFM7igtmbZ30g6BOIc" # it is just a sample -SENTENCES_FILE="./data/sentences.txt" # Putting an absolute path is recommended \ No newline at end of file +SENTENCES_FILES=['./data/sentences/default.txt'] # Putting an absolute path is recommended +# SENTENCES_DIRECTORIES=['./data/sentences/'] \ No newline at end of file diff --git a/data/sentences.txt b/data/sentences/default.txt similarity index 94% rename from data/sentences.txt rename to data/sentences/default.txt index 88c6ebe..7d5d4df 100644 --- a/data/sentences.txt +++ b/data/sentences/default.txt @@ -1,3 +1,4 @@ +발 닦고 잠이나 쭉 자고 싶어요 집에 가고 싶나요? 저도요... 월드콘은 맛있습니다. 오늘도 힘내세요! @@ -11,6 +12,7 @@ 좋은 하루 입니다! 좋은 하루 보내고 계신가요? ㅁㄴㅇㄹ +asdf 무슨 말을 할지 생각 중이에요. 인간 시대의 끝이 도래했다. 키보드 바꾸고 싶어요. diff --git a/data/sentences/hylasuwon.txt b/data/sentences/hylasuwon.txt new file mode 100644 index 0000000..6fc9780 --- /dev/null +++ b/data/sentences/hylasuwon.txt @@ -0,0 +1,2 @@ +수원청개구리는 멸종 위기에요! +수원청개구리, 맹꽁이\n다 멸종위기동물입니다 \ No newline at end of file diff --git a/data/sentences/worldcone_custom_emoji.txt b/data/sentences/worldcone_custom_emoji.txt new file mode 100644 index 0000000..db97454 --- /dev/null +++ b/data/sentences/worldcone_custom_emoji.txt @@ -0,0 +1,2 @@ +:dlcool: +:ablobcatdundundun: \ No newline at end of file diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 645a0ee..e5f9376 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -8,6 +8,7 @@ services: environment: - MISSKEY_INSTANCE_ADDRESS=worldc.one - MISSKEY_ACCESS_TOKEN=BWbGlK6lWuUgXQpFM7igtmbZ30g6BOIc - - SENTENCES_FILE=/data/sentences.txt + # - SENTENCES_FILES=['/data/sentences/default.txt'] + - SENTENCES_DIRECTORIES=['/data/sentences/'] volumes: - ./data:/data diff --git a/src/choose_sentence.py b/src/choose_sentence.py index 99a2380..c52511a 100644 --- a/src/choose_sentence.py +++ b/src/choose_sentence.py @@ -1,14 +1,33 @@ import random import os import sys +import json +from glob import glob from dotenv import load_dotenv load_dotenv() +_sentences=[] try: - with open(os.environ["SENTENCES_FILE"], "r") as f: - _sentences = f.readlines() + 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_FILES"): + sentence_files.extend(list(filter(os.path.isfile, json.loads(os.environ["SENTENCES_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')) + + if os.environ.get("SENTENCES_DIRECTORIES"): + # 원라인 똥 뿌직(터져도 책임 안짐) + sentence_files.extend([glob(f"{_dir}*.txt") for _dir in filter(os.path.isdir, json.loads(os.environ["SENTENCES_DIRECTORIES"]))][0]) + + 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}"]