feat(choose_sentence): 다중 파일, 다중 디렉토리 성택기능 추가
This commit is contained in:
parent
12f40fc30f
commit
75a1659734
|
@ -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
|
||||
SENTENCES_FILES=['./data/sentences/default.txt'] # Putting an absolute path is recommended
|
||||
# SENTENCES_DIRECTORIES=['./data/sentences/']
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue