| | import os |
| | import argparse |
| |
|
| | parser = argparse.ArgumentParser(description="Remove specified keywords from all text files in a directory.") |
| | parser.add_argument("folder_path", type=str, help="path to directory containing text files") |
| | parser.add_argument("-e", "--extension", type=str, default=".txt", help="file extension of text files to be processed (default: .txt)") |
| | args = parser.parse_args() |
| |
|
| | folder_path = args.folder_path |
| | extension = args.extension |
| | keywords = ["1girl", "solo", "blue eyes", "brown eyes", "blonde hair", "black hair", "realistic", "red lips", "lips", "artist name", "makeup", "realistic","brown hair", "dark skin", |
| | "dark-skinned female", "medium breasts", "breasts", "1boy"] |
| |
|
| | for file_name in os.listdir(folder_path): |
| | if file_name.endswith(extension): |
| | file_path = os.path.join(folder_path, file_name) |
| | with open(file_path, "r") as f: |
| | text = f.read() |
| | |
| | tags = [tag.strip() for tag in text.split(",")] |
| | |
| | tags = [tag for tag in tags if tag not in keywords] |
| | |
| | tags = [tag for tag in tags if tag.strip() != ""] |
| | |
| | with open(file_path, "w") as f: |
| | f.write(", ".join(tags)) |