#!/usr/bin/python3 # -*- coding: utf-8 -*- import argparse from pathlib import Path import shutil import re import pandas as pd from project_settings import project_path def get_args(): parser = argparse.ArgumentParser() parser.add_argument( "--data_dir", default=(project_path / "data").as_posix(), type=str ) parser.add_argument( "--output_file", default="metadata.csv", type=str ) args = parser.parse_args() return args def main(): args = get_args() data_dir = Path(args.data_dir) filename_list = data_dir.glob("*/*.txt") result = list() for filename in filename_list: name = filename.stem splits = name.split("_") idx = splits[-1] novel_name = "_".join(splits[:-1]) if name.__contains__(";") or name.__contains__("#"): print(filename.as_posix()) new_fliename = filename.as_posix() new_fliename = re.sub(r"&", " ", new_fliename) new_fliename = re.sub(r" ", " ", new_fliename) new_fliename = re.sub(r"quot;", "\"", new_fliename) new_fliename = re.sub(r"nbsp;", " ", new_fliename) new_fliename = re.sub(r"amp;", " ", new_fliename) new_fliename = re.sub(r"✘", "✘", new_fliename) new_fliename = re.sub(r"lt;", "", new_fliename) new_fliename = re.sub(r"gt;", "", new_fliename) new_fliename = str(new_fliename).replace(" ", "") new_fliename = str(new_fliename).replace("\"", "") new_fliename = re.sub(r"✘;", "✘", new_fliename) new_fliename = str(new_fliename).replace("#", "") print(new_fliename) shutil.move(filename.as_posix(), new_fliename) return if __name__ == '__main__': main()