Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77460281
ChangeImagePaths.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 14, 15:09
Size
1 KB
Mime Type
text/x-python
Expires
Fri, Aug 16, 15:09 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
19873949
Attached To
R3881 cp-change-image-paths
ChangeImagePaths.py
View Options
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
Log In to Comment