Created
October 1, 2022 11:21
-
-
Save hetima/7ff7c4b194a31123da9d8a93828c97a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# coding: UTF-8 | |
# digikam 月ごとのビューをアルバム(親フォルダ)に設定された日付で分類するようにデータベースを書き換えるスクリプト | |
# ついでに実行前のバックアップも作ります | |
import sqlite3 | |
import shutil | |
DB_PATH = r"G:\Data\DigiKam\digikam4.db" | |
DB_BACKUP_PATH = DB_PATH + "_bauckup" | |
def backup(): | |
shutil.copy2(DB_PATH, DB_BACKUP_PATH) | |
def update_date(): | |
dirs = {} | |
con = sqlite3.connect(DB_PATH) | |
cur = con.cursor() | |
for row in cur.execute('SELECT id, date FROM Albums'): | |
if row[0] is None or row[1] is None: | |
continue | |
if len(row[1])==10: | |
dirs[row[0]] = row[1] | |
updated = 0 | |
ignored = 0 | |
not_found = 0 | |
cur.execute('SELECT Images.album, ImageInformation.creationDate, ImageInformation.imageid FROM ImageInformation join Images on Images.id = ImageInformation.imageid') | |
images = cur.fetchall() | |
for row in images: | |
if row[0] is None or row[1] is None or row[2] is None: | |
not_found += 1 | |
continue | |
if dirs[row[0]] == row[1][:10]: | |
ignored += 1 | |
else: | |
new_time = dirs[row[0]] + "T01:00:00.000" | |
cur.execute('UPDATE ImageInformation SET creationDate=? WHERE imageid=?', (new_time, row[2])) | |
updated +=1 | |
print("UPDATED:" + str(updated)) | |
print("IGNORED:" + str(ignored)) | |
if not_found != 0: | |
print("NOTFOUND:" + str(not_found)) | |
con.commit() | |
con.close() | |
if __name__ == '__main__': | |
backup() | |
update_date() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment