Skip to content

Commit 0255951

Browse files
committed
fix: update collection mod time in anki-sync to force app reload
1 parent d103988 commit 0255951

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

scripts/python/anki_sync.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def collate(a, b):
2222
deck_id = row[0]
2323
else:
2424
deck_id = int(time.time() * 1000)
25-
# Using empty blobs for common and kind as per schema
2625
cur.execute(
2726
'INSERT INTO decks (id, name, mtime_secs, usn, common, kind) '
2827
'VALUES (?, ?, ?, -1, ?, ?)',
@@ -33,6 +32,7 @@ def collate(a, b):
3332
with open(file_path, 'r') as f:
3433
content = f.read().split('---')
3534

35+
cards_added = 0
3636
for card in content:
3737
if '?' in card:
3838
parts = [part.strip() for part in card.split('?', 1)]
@@ -60,11 +60,18 @@ def collate(a, b):
6060
'0, 0, 0, 0, 0, "")',
6161
(ts + 1, nid, deck_id, int(time.time()))
6262
)
63+
cards_added += 1
6364
except sqlite3.Error:
6465
continue
66+
67+
# 3. CRITICAL: Update collection mod time to force AnkiDroid reload
68+
if cards_added > 0:
69+
cur.execute('UPDATE col SET mod = ?', (int(time.time() * 1000),))
70+
6571
conn.commit()
6672
conn.close()
73+
print(f"Cards added: {cards_added}")
6774

6875

6976
if __name__ == "__main__":
70-
sync()
77+
sync()

0 commit comments

Comments
 (0)