I have my pictures organized by events already on my computer. When I import the pictures, events get split up in day-events, which are often shorter than the real events. I don’t want to group 10 years of pictures by hand and also I like programming. The DB is simply SQLite, so it should be possible to modify it from the outside, to import pics through python, right?
I read a bit in the shotwell wiki & wrote a python script to
- create events in the EventTable for each parent directory of the pictures in the PhotoTable
- set the event_id of each picture to the right new event.
When I open Shotwell it works, I have my pics organized in events! However, if I import new pictures through shotwell & close Shotwell and want to open it again, it won’t open anymore. Without adding new pictures I can close and re-open.
Here’s the code
db_path = 'sqlite:////home/mfrick/.local/share/shotwell/data/photo.db'
dbEngine=sqlalchemy.create_engine(db_path)
df = pd.read_sql('select * from PhotoTable', dbEngine)
df['Event'] = df['filename'].apply(lambda p: pl.Path(p).parent.name)
events = df['Event'].unique()
for i_event, dir_name in enumerate(events):
df.loc[df['Event'] == dir_name, 'event_id'] = int(i_event + 1)
df = df.drop(columns='Event')
df.to_sql(name ='PhotoTable', con=dbEngine, index=False, if_exists='replace',
dtype=dtypes_photo)
df = pd.read_sql('select * from EventTable', dbEngine)
df = df[:0] # Only keep the columns structure
for i_event, event_name in enumerate(events):
new_line = np.array([np.nan]*len(df.columns)).reshape((1,-1))
new_line = pd.DataFrame(new_line, columns=df.columns)
new_line['time_created'] = int(time.time())
new_line['id'] = int(i_event + 1)
new_line['name'] = event_name
df = pd.concat((df, new_line))
df.to_sql(name ='EventTable', con= dbEngine, index=False, if_exists='replace',
dtype=dtypes_event)
I haven’t found out how to set the default values of the columns yet, but I tried to set them manually in a GUI based DB Browser after running my script & before opening shotwell & it didn’t help.
Any ideas?