py/gadict_srs_anki.py
changeset 556 78bf1097106a
parent 555 4a3188fc8951
child 559 2b03300f610c
equal deleted inserted replaced
555:4a3188fc8951 556:78bf1097106a
    78   font-size: 20px;
    78   font-size: 20px;
    79   text-align: center;
    79   text-align: center;
    80   color: black;
    80   color: black;
    81   background-color: white;
    81   background-color: white;
    82 }
    82 }
       
    83 .ask {
       
    84   margin-bottom: 1.2em;
       
    85 }
    83 span.headword {
    86 span.headword {
    84   font-style: italic;
    87   font-weight: bolt;
    85 }
    88 }
    86 .pron {
    89 .pron {
    87   color: magenta;
    90   color: magenta;
    88 }
    91 }
    89 .pos {
    92 .pos {
    96 }
    99 }
    97 .ant {
   100 .ant {
    98   color: red;
   101   color: red;
    99 }
   102 }
   100 .syn {
   103 .syn {
       
   104   color: blue;
       
   105 }
       
   106 .attrs {
   101   color: blue;
   107   color: blue;
   102 }
   108 }
   103 """
   109 """
   104 
   110 
   105         collection.models.addField(model, collection.models.newField('From'))
   111         collection.models.addField(model, collection.models.newField('From'))
   146     builder = AnkiDbBuilder(TMPDIR, FBASENAME)
   152     builder = AnkiDbBuilder(TMPDIR, FBASENAME)
   147 
   153 
   148     for (headwords, translations) in DOM[1:]:
   154     for (headwords, translations) in DOM[1:]:
   149         identity = headwords[0].headword
   155         identity = headwords[0].headword
   150         buf = []
   156         buf = []
       
   157         v1, v2, v3 = (None, None, None)
       
   158         singular, plural = (None, None)
   151         for hw in headwords:
   159         for hw in headwords:
   152             buf.append("<div clsas='headword'>")
   160             buf.append("<div clsas='headword'>")
   153             buf.append("<span clsas='headword'>")
   161             buf.append("<span clsas='headword'>")
   154             buf.append(hw.headword)
   162             buf.append(hw.headword)
   155             buf.append("</span>")
   163             buf.append("</span>")
   161                 l = [u"«"+x+u"»" for x in hw.attrs]
   169                 l = [u"«"+x+u"»" for x in hw.attrs]
   162                 l.sort()
   170                 l.sort()
   163                 buf.append("<span class='attrs'>")
   171                 buf.append("<span class='attrs'>")
   164                 buf.append(", ".join(l))
   172                 buf.append(", ".join(l))
   165                 buf.append("</span>")
   173                 buf.append("</span>")
       
   174             if 'v1' in hw.attrs:
       
   175                 v1 = (hw.headword, hw.pron)
       
   176             if 'v2' in hw.attrs:
       
   177                 v2 = (hw.headword, hw.pron)
       
   178             if 'v3' in hw.attrs:
       
   179                 v3 = (hw.headword, hw.pron)
       
   180             if 's' in hw.attrs:
       
   181                 singular = (hw.headword, hw.pron)
       
   182             if 'pl' in hw.attrs:
       
   183                 plural = (hw.headword, hw.pron)
   166             buf.append("</div>")
   184             buf.append("</div>")
   167         direct_from = "".join(buf)
   185         direct_from = "".join(buf)
   168         buf = []
   186         buf = []
   169         for sense in translations:
   187         for sense in translations:
   170             buf.append("<div class='sense'>")
   188             buf.append("<div class='sense'>")
   199                     buf.append(tr)
   217                     buf.append(tr)
   200                     buf.append("</span>")
   218                     buf.append("</span>")
   201         direct_to = "".join(buf)
   219         direct_to = "".join(buf)
   202         builder.add_note("en->tr", identity, direct_from, direct_to)
   220         builder.add_note("en->tr", identity, direct_from, direct_to)
   203         builder.add_note("tr->en", identity, direct_to, direct_from)
   221         builder.add_note("tr->en", identity, direct_to, direct_from)
       
   222         if v1 and v2 and v3:
       
   223             question = u"<div class='ask'>Find irregular verb:</div>"
       
   224             riddle1 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v1</span>".format(v1[0], v1[1])
       
   225             riddle2 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v2</span>".format(v2[0], v2[1])
       
   226             riddle3 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v3</span>".format(v3[0], v3[1])
       
   227             answer = u"{}<br>{}<br>{}<br>{}".format(riddle1, riddle2, riddle3, direct_to)
       
   228             builder.add_note("irregular1", identity, question + riddle1, answer)
       
   229             builder.add_note("irregular2", identity, question + riddle2, answer)
       
   230             builder.add_note("irregular3", identity, question + riddle3, answer)
       
   231         if singular and plural:
       
   232             question = u"<div class='ask'>Find plural:</div>"
       
   233             riddle_s = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>s</span>".format(singular[0], singular[1])
       
   234             riddle_pl = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>pl</span>".format(plural[0], plural[1])
       
   235             answer = u"{}<br>{}<br>{}".format(riddle_s, riddle_pl, direct_to)
       
   236             builder.add_note("singular", identity, question + riddle_s, answer)
       
   237             builder.add_note("plural", identity, question + riddle_pl, answer)
       
   238 
   204 
   239 
   205     builder.export(FONAME)
   240     builder.export(FONAME)
   206 finally:
   241 finally:
   207     builder.close()
   242     builder.close()
   208     shutil.rmtree(TMPDIR, ignore_errors=True)
   243     shutil.rmtree(TMPDIR, ignore_errors=True)