Newer
Older
anonimizer / anonimizer.py
import csv
import os


def process(year):
    csv_file = f"{year}.csv"
    target_dir = r"D:\usr\prog\STASanonimizer\stas"
    target_dir = r"\\gabor\Data\ThoracicSurgery\STAS"
    target_dir = os.path.join(target_dir, f"{year}手術症例")
    with open(csv_file, "r") as f:
        reader = csv.reader(f)
        data = list(reader)
        num_succeess = 0
        num_error = 0
        for row in data[1:]:
            dir_from = os.path.join(target_dir, row[0])
            dir_to = os.path.join(target_dir, row[1])
            check = os.path.exists(dir_from)
            if not check:
                print(f"{dir_from} not exist")
                num_error += 1
            else:
                os.rename(dir_from, dir_to)
                print(f"RENAME {dir_from} -> {dir_to}")
                num_succeess += 1
    return num_succeess, num_error


if __name__ == "__main__":
    years = [2017, 2018, 2019]
    num_succeess = 0
    num_error = 0
    for year in years:
        s, e = process(year)
        num_succeess += s
        num_error += e
    print(f"success {num_succeess}, error {num_error}")