import csv
import time
from datetime import datetime

from PyQt5.QtWidgets import QApplication

from src.components.os_label_printer import *
from src.lib.helpers import ConfigReader

SYSTEM_ID = "st-ten-12"
CSV_PATH="src/scripts/ristampa.csv"
TEMPLATE="ETA30x16_203dpi.prn"
config = ConfigReader(system_id=SYSTEM_ID)
printer=Os_Label_Printer(config=config,name="label_printer")


# timenow = datetime.now()
app = QApplication(sys.argv)

with open(CSV_PATH, "r", encoding="utf-8-sig") as f:
    reader = csv.DictReader(f)
    for row in reader:
        sn=row["part_number"]
        print(f"PRINTING LABEL # {sn}")
        context = {
            # RECIPE DATA
            "PART": row["part_number"],
            # SERIAL DEFINITION
            "SN5": row["seriale"],
            # TIME DEFINITION
            "DATE": row["data"],
            "TIME": row["ora"],

            }
        printer.print_label(TEMPLATE,context)

        time.sleep(1)