Page MenuHomec4science

ChangeImagePaths.py
No OneTemporary

File Metadata

Created
Wed, Aug 14, 15:09

ChangeImagePaths.py

import sqlite3
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
sqlite_path = filedialog.askopenfilename(title = "Please provide your SQLite Database file")
image_path = filedialog.askdirectory(title = "Directory of images")
# Connect
conn = sqlite3.connect(sqlite_path)
c = conn.cursor()
# Find 'image_table' and 'image_names'
c.execute('Select value FROM Experiment_Properties WHERE field=\'image_table\'')
result = c.fetchone()
image_table=result[0]
c.execute('Select value FROM Experiment_Properties WHERE field=\'image_names\'')
result = c.fetchone()
image_names=result[0].split(',')
# Now change in image_table the values of all columns containing Image_PathName_...
# Set the path to a folder behind the current one where there is the images folder
for image in image_names:
c.execute("UPDATE %s SET Image_PathName_%s = '%s'" % (image_table, image,image_path))
# Change the location of the sql file
c.execute("UPDATE Experiment_Properties SET value=? WHERE field='db_sqlite_file'", [sqlite_path])
# Save to the mysqldb
conn.commit()
conn.close()

Event Timeline