from pathlib import Path
import csv


def get_csv(path: Path) -> list:
    """
    Read CSV with lead column like HEADER (1), COMMENT (0..N), DATA (1..N).
    :param path: Path of the csv-file (;-separated)
    :return: list(dict) with keys like in HEADER row.
    """

    def map_line(line: list, fields: dict) -> dict:
        d = {}
        for k in fields:
            d[fields[k]] = line[k]
        return d

    with open(path) as fp:
        reader = csv.reader(fp, delimiter=';', quotechar='"')
        header = next(reader)
        assert header[0].endswith("HEADER")
        fields = {}
        for i in range(1, len(header)):
            if header[i]:
                fields[i] = header[i]
        data = []
        for row in reader:
            if row[0].endswith("COMMENT"):
                continue
            data.append(map_line(row, fields))
        return data