From f9005f7cddd9c81d66355b5d8ce5b0e70d0970bd Mon Sep 17 00:00:00 2001 From: kdh8219 Date: Fri, 22 Dec 2023 22:03:06 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat(choose=5Fsentence):=20=EB=94=94?= =?UTF-8?q?=EB=A0=89=ED=86=A0=EB=A6=AC=20=EB=8B=A8=EC=9C=84=20sentence=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?add(sentences):=20sentence=20=EC=B6=94=EA=B0=80(=ED=85=8C?= =?UTF-8?q?=EB=A7=88=EB=B3=84=EB=A1=9C=20=EB=B6=84=EB=A6=AC,=20=EC=89=AC?= =?UTF-8?q?=EC=9A=B4=20=EC=BB=A4=EC=8A=A4=ED=85=80.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .example.env | 2 +- data/{sentences.txt => sentences/default.txt} | 2 ++ data/sentences/hylasuwon.txt | 1 + data/sentences/worldcone_custom_emoji.txt | 2 ++ docker-compose.example.yml | 3 ++- src/choose_sentence.py | 27 ++++++++++++++----- 6 files changed, 29 insertions(+), 8 deletions(-) rename data/{sentences.txt => sentences/default.txt} (94%) create mode 100644 data/sentences/hylasuwon.txt create mode 100644 data/sentences/worldcone_custom_emoji.txt diff --git a/.example.env b/.example.env index f12b746..05bc03b 100644 --- a/.example.env +++ b/.example.env @@ -1,4 +1,4 @@ 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_FILE="./data/sentences/sentences.txt" # Putting an absolute path is recommended \ 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..839966e --- /dev/null +++ b/data/sentences/hylasuwon.txt @@ -0,0 +1 @@ +수원청개구리는 멸종 위기에요! \ 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..6a3a3bb 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_FILE=/data/sentences.txt + - SENTENCES_DIRECTORY=/data/sentences/ volumes: - ./data:/data diff --git a/src/choose_sentence.py b/src/choose_sentence.py index 99a2380..93a0bd3 100644 --- a/src/choose_sentence.py +++ b/src/choose_sentence.py @@ -1,17 +1,32 @@ import random import os import sys +from glob import glob from dotenv import load_dotenv load_dotenv() -try: - with open(os.environ["SENTENCES_FILE"], "r") as f: - _sentences = f.readlines() -except: - e = sys.exc_info()[1] - _sentences = [f"에러발생(진짜임): {e}"] +_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) + +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}"] # choose random sentence in google spread sheet def chooseSentence() -> str: From c6de8dd789a3278a74c9638106aa44fcd5e632dd Mon Sep 17 00:00:00 2001 From: kdh8219 Date: Fri, 22 Dec 2023 22:05:20 +0900 Subject: [PATCH 2/6] =?UTF-8?q?fix(env):=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EA=B8=B0=EB=B3=B8=20sentence=20=ED=8C=8C=EC=9D=BC=20=EC=A7=80?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .example.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.example.env b/.example.env index 05bc03b..1c529c7 100644 --- a/.example.env +++ b/.example.env @@ -1,4 +1,4 @@ MISSKEY_INSTANCE_ADDRESS="worldc.one" MISSKEY_ACCESS_TOKEN="BWbGlK6lWuUgXQpFM7igtmbZ30g6BOIc" # it is just a sample -SENTENCES_FILE="./data/sentences/sentences.txt" # Putting an absolute path is recommended \ No newline at end of file +SENTENCES_FILE="./data/sentences/default.txt" # Putting an absolute path is recommended \ No newline at end of file From 12f40fc30ffa0aab98fb0c99196967ba3d607d53 Mon Sep 17 00:00:00 2001 From: kdh8219 Date: Fri, 22 Dec 2023 22:07:45 +0900 Subject: [PATCH 3/6] =?UTF-8?q?fix(choose=5Fsentence):=20=EB=AF=B8?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EB=90=9C=20=EC=BD=94=EB=93=9C=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=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: From 75a1659734ee98d67974f4c59210f489b612cde7 Mon Sep 17 00:00:00 2001 From: kdh8219 Date: Sat, 23 Dec 2023 19:20:18 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat(choose=5Fsentence):=20=EB=8B=A4?= =?UTF-8?q?=EC=A4=91=20=ED=8C=8C=EC=9D=BC,=20=EB=8B=A4=EC=A4=91=20?= =?UTF-8?q?=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20=EC=84=B1=ED=83=9D?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .example.env | 3 ++- docker-compose.example.yml | 4 ++-- src/choose_sentence.py | 11 ++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.example.env b/.example.env index 1c529c7..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/default.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/docker-compose.example.yml b/docker-compose.example.yml index 6a3a3bb..e5f9376 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -8,7 +8,7 @@ services: environment: - MISSKEY_INSTANCE_ADDRESS=worldc.one - MISSKEY_ACCESS_TOKEN=BWbGlK6lWuUgXQpFM7igtmbZ30g6BOIc - # - SENTENCES_FILE=/data/sentences.txt - - SENTENCES_DIRECTORY=/data/sentences/ + # - 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 82e10e7..7691f7b 100644 --- a/src/choose_sentence.py +++ b/src/choose_sentence.py @@ -1,6 +1,7 @@ import random import os import sys +import json from glob import glob from dotenv import load_dotenv @@ -10,12 +11,20 @@ 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_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"]))]) + for sentence_file in sentence_files: with open(sentence_file, "r") as f: _sentences.extend(f.readlines()) From 97c5a63bb802ebb9f0d7bc0c6b75d82511ae5e25 Mon Sep 17 00:00:00 2001 From: kdh8219 Date: Sat, 23 Dec 2023 19:21:50 +0900 Subject: [PATCH 5/6] =?UTF-8?q?docs(sentence):=20=EB=A7=B9=EA=BD=81?= =?UTF-8?q?=EB=8B=98=20=EB=B0=9C=EC=96=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/sentences/hylasuwon.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/sentences/hylasuwon.txt b/data/sentences/hylasuwon.txt index 839966e..6fc9780 100644 --- a/data/sentences/hylasuwon.txt +++ b/data/sentences/hylasuwon.txt @@ -1 +1,2 @@ -수원청개구리는 멸종 위기에요! \ No newline at end of file +수원청개구리는 멸종 위기에요! +수원청개구리, 맹꽁이\n다 멸종위기동물입니다 \ No newline at end of file From 9258c87260045bd367e88eb1349a4e35bbe4b960 Mon Sep 17 00:00:00 2001 From: kdh8219 Date: Sat, 23 Dec 2023 19:33:28 +0900 Subject: [PATCH 6/6] =?UTF-8?q?fix(choose=5Fsentence):=20=EB=8B=A4?= =?UTF-8?q?=EC=A4=91=20=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20=ED=8C=8C?= =?UTF-8?q?=EC=8B=B1=EC=8B=9C=EC=97=90=20=EB=AC=B8=EC=A0=9C=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=ED=95=98=EB=8D=98=EA=B1=B0=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/choose_sentence.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/choose_sentence.py b/src/choose_sentence.py index 7691f7b..c52511a 100644 --- a/src/choose_sentence.py +++ b/src/choose_sentence.py @@ -11,7 +11,7 @@ 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"]) @@ -23,7 +23,7 @@ try: 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"]))]) + 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: