|
|
|
|
|
import argparse |
|
from pathlib import Path |
|
import shutil |
|
|
|
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]) |
|
|
|
result.append({ |
|
"source": filename.parts[-2], |
|
"idx": idx, |
|
"filename": "/".join(filename.parts[-3:]), |
|
"novel_name": novel_name |
|
}) |
|
|
|
result = pd.DataFrame(result) |
|
result.to_csv(args.output_file, index=False, encoding="utf_8_sig") |
|
return |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
|
|