From 75a1659734ee98d67974f4c59210f489b612cde7 Mon Sep 17 00:00:00 2001 From: kdh8219 Date: Sat, 23 Dec 2023 19:20:18 +0900 Subject: [PATCH] =?UTF-8?q?feat(choose=5Fsentence):=20=EB=8B=A4=EC=A4=91?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC,=20=EB=8B=A4=EC=A4=91=20=EB=94=94?= =?UTF-8?q?=EB=A0=89=ED=86=A0=EB=A6=AC=20=EC=84=B1=ED=83=9D=EA=B8=B0?= =?UTF-8?q?=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())