File: update_modification%20time.py

package info (click to toggle)
mnemosyne 2.4-0.1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,500 kB
  • ctags: 2,986
  • sloc: python: 23,019; makefile: 153
file content (34 lines) | stat: -rw-r--r-- 964 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import copy
from mnemosyne.script import Mnemosyne

from mnemosyne.libmnemosyne.utils import MnemosyneError

# 'data_dir = None' will use the default system location, edit as appropriate.
data_dir = "C:\dot_test"
mnemosyne = Mnemosyne(data_dir)

created = {}
modified = {}

for _card_id, _fact_id in mnemosyne.database().cards():
    card = mnemosyne.database().card(_card_id, is_id_internal=True)
    created[card.id] = card.creation_time
    modified[card.id] = card.modification_time
mnemosyne.finalise()

# write

data_dir = None
mnemosyne = Mnemosyne(data_dir)

for id in created:
    print(id)
    mnemosyne.database().con.execute("""update cards set creation_time=?, modification_time=?
        where id=?""", (created[id], modified[id], id))
    try:
        card = mnemosyne.database().card(id, is_id_internal=False)
        mnemosyne.log().edited_card(card)
    except MnemosyneError:
        pass
mnemosyne.finalise()