优化效率

This commit is contained in:
douboer
2025-08-12 15:05:29 +08:00
parent 3eaaf8ad2b
commit e55178e316
67 changed files with 19174 additions and 46 deletions

View File

@@ -13,9 +13,41 @@ def parse_books_plist(plist_path):
'type': book.get('BKBookType', ''),
'bookid': bk_id,
'itemname': book.get('itemName', ''),
'path': book.get('path', '')
'path': book.get('path', ''),
'date': book.get('BKInsertionDate',''),
'updatedate': book.get('updateDate','')
}
return booksinfo
import sqlite3
import os
def get_books_last_open(db_path='data/BKLibrary.sqlite'):
"""
从BKLibrary.sqlite获取书籍最近打开时间
返回defaultdict(dict)bk_id为索引包含最近打开时间
"""
books_open = defaultdict(dict)
if not os.path.exists(db_path):
return books_open
try:
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# ZBKLIBRARYASSET表包含书籍信息
cursor.execute(''' SELECT ZASSETID, zlastopendate FROM ZBKLIBRARYASSET WHERE zlastopendate IS NOT NULL
''')
rows = cursor.fetchall()
for row in rows:
asset_id, last_open = row
if asset_id:
books_open[asset_id] = {
'last_open': last_open # 苹果时间戳基准时间为2001-01-01
}
conn.close()
except Exception as e:
print(f'警告: 读取BKLibrary.sqlite失败: {e}')
return books_open
if __name__ == '__main__':
booksinfo = parse_books_plist('./data/Books.plist')
@@ -33,4 +65,12 @@ if __name__ == '__main__':
pprint(v, sort_dicts=False, indent=2)
print('-' * 60)
'''
# 测试最近打开时间
print("\n【最近打开时间示例】")
books_open = get_books_last_open()
import datetime
for k, v in list(books_open.items())[:3]:
ts = v['last_open']
# 苹果时间戳基准2001-01-01
dt = datetime.datetime(2001, 1, 1) + datetime.timedelta(seconds=ts)
print(f"{k}: {dt} (timestamp: {ts})")