import sys
import csv
import pandas
from collections import defaultdict
import uuid

if __name__ == "__main__":
    f_name = sys.argv[1]

    l = []

    with open(f_name, "r") as f:
        c = csv.reader(f, delimiter=";")

        pal_dict = {}

        for r in c:
            p = str(r[2])

            if r[1] == "TP 8":
                pal_dict[p] = p + "_" + str(r[0])

            l.append([r[0], r[1], pal_dict.get(p, p + "_0"), r[3]])
            # l[3] = pal_dict.get(p, p + "_0")

    with open("gefixt.csv", "w", newline="") as f_w:
        c_w = csv.writer(f_w, delimiter=";")
        c_w.writerows(l)
