import sqlite3, os


here_i_am = os.path.dirname(os.path.abspath(__file__)) 
#db_file = here_i_am + r"\\Endless Feed.db"
db_file = here_i_am + r"\\MASTER.db"

conn = None                        
try:
    conn = sqlite3.connect(db_file) 
                 
except:
    print("Create_Connection")        
    print("conn error")

cur =conn.cursor()
cur.execute("ALTER TABLE URI_Change ADD COLUMN DISPLAY_DATE integer")
conn.commit()

cur = conn.cursor()
cur.execute("ALTER TABLE Last_Played_Tracks ADD COLUMN DISPLAY_DATE integer")
conn.commit()

cur = conn.cursor()
cur.execute("SELECT * FROM URI_Change")
rows = cur.fetchall()
for row in rows:
    olddate = row[0]
    mth = olddate[:2]
    dy = olddate[3:5]
    newdate = dy + "-" + mth + olddate[5:]
    print(newdate, end='\r')
    cur.execute("UPDATE URI_Change SET DISPLAY_DATE = '" + newdate + "' WHERE DATE_OF_CHANGE = '" + olddate + "'")
    conn.commit()


cur = conn.cursor()
cur.execute("SELECT * FROM Last_Played_Tracks")
rows = cur.fetchall()
for row in rows:
    olddate = row[3]
    mth = olddate[:2]
    dy = olddate[3:5]
    newdate = dy + "-" + mth + olddate[5:]
    print(newdate, end='\r')
    cur.execute("UPDATE Last_Played_Tracks SET DISPLAY_DATE = '" + newdate + "' WHERE LAST_PLAYED = '" + olddate + "'")
    conn.commit()
