import csv
import uuid

from path import Path


SRC = "E:\Backlog\backlog_db.sqlite3.20181026"
DST = "E:\Backlog\backlog_db_new.sqlite3"

DIR = Path(r"E:\Backlog\tmp")

csv_path = DIR / "main_sprint.csv"
with open(csv_path, "r") as fcsv, open(csv_path + ".new", "w+", newline='') as fnew:
    reader = csv.reader(fcsv, delimiter='|', quotechar='"')
    writer = csv.writer(fnew, delimiter='|', quotechar='"')
    first = True
    for row in reader:
        newrow = row
        if first:
            newrow.insert(3, 'uuid')
            first = False
        else:
            newrow.insert(3, uuid.uuid4())
        writer.writerow(newrow)
        

csv_path = DIR / "main_project.csv"
with open(csv_path, "r") as fcsv, open(csv_path + ".new", "w+", newline='') as fnew:
    reader = csv.reader(fcsv, delimiter='|', quotechar='"')
    writer = csv.writer(fnew, delimiter='|', quotechar='"')
    first = True
    for row in reader:
        del row[4]
        newrow = row
        if first:
            newrow.insert(3, 'uuid')
            newrow.append('color')
            first = False
        else:
            newrow.insert(3, uuid.uuid4())
            newrow.append('')
        writer.writerow(newrow)

csv_path = DIR / "main_epic.csv"
with open(csv_path, "r") as fcsv, open(csv_path + ".new", "w+", newline='') as fnew:
    reader = csv.reader(fcsv, delimiter='|', quotechar='"')
    writer = csv.writer(fnew, delimiter='|', quotechar='"')
    first = True
    for row in reader:
        newrow = row
        if first:
            newrow.insert(3, 'uuid')
            first = False
        else:
            newrow.insert(3, uuid.uuid4())
        writer.writerow(newrow)
        
csv_path = DIR / "main_story.csv"
with open(csv_path, "r") as fcsv, open(csv_path + ".new", "w+", newline='') as fnew:
    reader = csv.reader(fcsv, delimiter='|', quotechar='"')
    writer = csv.writer(fnew, delimiter='|', quotechar='"')
    first = True
    for row in reader:
        newrow = row
        if first:
            newrow.insert(3, 'uuid')
            first = False
        else:
            newrow.insert(3, uuid.uuid4())
        writer.writerow(newrow)
        

