Add a way to mark card for deletion.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sat, 15 Oct 2016 11:09:33 +0300
changeset 608 01fcbb1d5cea
parent 607 a8ee8f8d38f3
child 609 e4685f0b797b
Add a way to mark card for deletion.
Makefile
obsolete/gadict_en-ru+uk.del
py/gadict_srs_anki.py
--- a/Makefile	Sat Oct 15 02:38:10 2016 +0300
+++ b/Makefile	Sat Oct 15 11:09:33 2016 +0300
@@ -410,6 +410,9 @@
 .PHONY: anki
 anki: $(SRS_ANKI_FILES)
 
+dist/srs/%.apkg: %.gadict %.del py/gadict.py py/gadict_srs_anki.py $(MAKEFILE_LIST) | dist/srs/
+	PYTHONPATH=/usr/share/anki: python -B py/gadict_srs_anki.py $< $@
+
 dist/srs/%.apkg: %.gadict py/gadict.py py/gadict_srs_anki.py $(MAKEFILE_LIST) | dist/srs/
 	PYTHONPATH=/usr/share/anki: python -B py/gadict_srs_anki.py $< $@
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/obsolete/gadict_en-ru+uk.del	Sat Oct 15 11:09:33 2016 +0300
@@ -0,0 +1,8 @@
+shrive
+begird
+chide
+grave
+stave
+throughly
+bespit
+crow
--- a/py/gadict_srs_anki.py	Sat Oct 15 02:38:10 2016 +0300
+++ b/py/gadict_srs_anki.py	Sat Oct 15 11:09:33 2016 +0300
@@ -52,6 +52,12 @@
 FBASENAME, _ = os.path.splitext(os.path.basename(FONAME))
 TMPDIR = tempfile.mkdtemp(dir = os.path.dirname(FONAME))
 
+try:
+    FDEL = io.open(FBASENAME+".del", mode='r', buffering=1, encoding="utf-8")
+except:
+    FDEL = None
+
+
 import hashlib
 
 import anki
@@ -119,6 +125,10 @@
 span.glos {
   font-size: .95em;
 }
+.del {
+  color: red;
+  font-weight: bold;
+}
 """
 
         collection.models.addField(model, collection.models.newField('From'))
@@ -145,12 +155,16 @@
         h = hashlib.md5(":".join((self.name, type_, headword)))
         return h.hexdigest()
 
-    def add_note(self, type_, id_, from_, to_):
+    def add_note(self, type_, id_, from_, to_, tags_ = None):
         note = self.collection.newNote()
         note['From'] = from_
         # print(from_)
         note['To'] = to_
         # print(to_)
+        if isinstance(tags_, str):      note.tags = [tags_]
+        elif isinstance(tags_, list):   note.tags = tags_
+        elif tags_ is None:             pass
+        else:                           raise Exception('Expect string or list of tags...')
         note.guid = self.guid(type_, id_)
         self.collection.addNote(note)
 
@@ -216,6 +230,17 @@
 try:
     builder = AnkiDbBuilder(TMPDIR, FBASENAME)
 
+    for identity in FDEL or []:
+        identity = identity.strip()
+        warnmsg = "<div class='del'>Please delete this note ({})</div>".format(identity)
+        builder.add_note("en->tr", identity, warnmsg, warnmsg+" en->tr", "del")
+        builder.add_note("tr->en", identity, warnmsg, warnmsg+" tr->en", "del")
+        builder.add_note("irregular1", identity, warnmsg, warnmsg+" irregular1", "del")
+        builder.add_note("irregular2", identity, warnmsg, warnmsg+" irregular2", "del")
+        builder.add_note("irregular3", identity, warnmsg, warnmsg+" irregular3", "del")
+        builder.add_note("singular", identity, warnmsg, warnmsg+" singular", "del")
+        builder.add_note("plural", identity, warnmsg, warnmsg+" plural", "del")
+
     for (headwords, translations) in DOM[1:]:
         identity = headwords[0].headword
         buf = []
@@ -275,7 +300,6 @@
             builder.add_note("singular", identity, question + riddle_s, answer)
             builder.add_note("plural", identity, question + riddle_pl, answer)
 
-
     builder.export(FONAME)
 finally:
     builder.close()