在 MySQL 中编辑命令行 Anki 抽认卡

在 MySQL 中编辑命令行 Anki 抽认卡

我需要在 77777 中做一个小改动安基抽认卡,最好以编程方式,而不是使用他们的替换工具,这是不够的。我最初将数据作为 CSV 文件导入,这样数据很容易修改。我得到了他们的答复支持:他们使用 MySQL 作为数据库:

好吧,首先,我认为你需要了解 MySQL 数据库的读写操作。如果你不了解,我就不多说了。

例如,我想知道它们的数据库模式。我想在一个 Deck 上运行的示例伪命令

sed s/;/1)/ [anki-deck's-cards]

其中仅匹配换行符的第一个条目。实际上,要求是做一些简单的算术。我不知道他们的 MySQL 连接器详细信息。我想了解他们的 MySQL 详细信息的概述。

如何在 Anki Flashcards 的 Deck 中编辑卡片?

答案1

apkg 文件包含一个嵌入的 sqlite 数据库文件。例如 deck南美洲的首都下载为 Capital_Cities_of_South_America.apkg,实际上是一个 zip 文件。解压后会提取几个文件

$ unzip ../Capital_Cities_of_South_America.apkg
Archive:  ../Capital_Cities_of_South_America.apkg
  inflating: collection.anki2        
 extracting: 0                       
 extracting: 1                       
 extracting: 2                       
 extracting: 3                       
 extracting: 4                       
 extracting: 5                       
 extracting: 6                       
 extracting: 7                       
 extracting: 8                       
 extracting: 9                       
 extracting: 10                      
 extracting: 11                      
  inflating: media                   
$

但有趣的是 collection.anki2,它是一个 sqlite 文件。

$ sqlite3 collection.anki2   
SQLite version 3.13.0 2016-05-18 10:57:30
Enter ".help" for usage hints.
sqlite> .tables
cards   col     graves  notes   revlog
sqlite> .dump notes
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE notes (
    id              integer primary key,   /* 0 */
    guid            text not null,         /* 1 */
    mid             integer not null,      /* 2 */
    mod             integer not null,      /* 3 */
    usn             integer not null,      /* 4 */
    tags            text not null,         /* 5 */
    flds            text not null,         /* 6 */
    sfld            integer not null,      /* 7 */
    csum            integer not null,      /* 8 */
    flags           integer not null,      /* 9 */
    data            text not null          /* 10 */
);
INSERT INTO "notes" VALUES(1475868715241,'P1Dh$4r;;P',1475850444584,1476205558,13,' South_America capitals ','Capital of French Guiana?Cayenne<div><br /></div><div><img src="053_Hood_135.jpg" /></div>','Capital of French Guiana?',511387741,0,'');
INSERT INTO "notes" VALUES(1476020723949,'D3h>i:~1(}',1475850444584,1476205484,13,' South_America capitals ','Capital of Brazil?Brasilia<div><br /></div><div><img src="brasilia-006.jpg" /></div>','Capital of Brazil?',139249191,0,'');
INSERT INTO "notes" VALUES(1476020740304,'I=w5}{qq&z',1475850444584,1476021426,4,' South_America capitals ','Capital of Argentina?Buenos Aires','Capital of Argentina?',4279953785,0,'');
INSERT INTO "notes" VALUES(1476020761836,'PpW<QQ2n;<',1475850444584,1476205269,13,' South_America capitals ','Capital of Chile?Santiago<div><br /></div><div><img src="santiago.jpg" /><br /><div><br /></div><div><br /></div></div>','Capital of Chile?',857145718,0,'');
INSERT INTO "notes" VALUES(1476020893034,'AQILm-om{w',1475850444584,1476205286,13,' South_America capitals ','Capital of Suriname?Paramaribo<div><br /></div><div><img src="paste-68513318306560.jpg" /><br /><div><br /></div><div><br /></div></div>','Capital of Suriname?',3475624840,0,'');
INSERT INTO "notes" VALUES(1476021133011,'ssX|ur}vz;',1475850444584,1476205460,13,' South_America capitals ','Capital of Guyana?Georgetown<div><br /></div><div><img src="georgetown-guyana.jpg" /></div>','Capital of Guyana?',1383243232,0,'');
INSERT INTO "notes" VALUES(1476021159549,'d_}(&UOcN0',1475850444584,1476205474,13,' South_America capitals ','Capital of Venezuela?Caracas<div><br /></div><div><img src="CaracasAvila.jpg" /></div>','Capital of Venezuela?',3460219780,0,'');
INSERT INTO "notes" VALUES(1476021305082,'hF6^dUFOU_',1475850444584,1476205202,13,' South_America capitals ','Capital of Colombia?Bagota<div><br /></div><div><!--anki--><img src="asuncion-paraguay.jpg" /></div>','Capital of Colombia?',3745298320,0,'');
INSERT INTO "notes" VALUES(1476021329578,'BF<CKCw&@X',1475850444584,1476021353,4,' South_America capitals ','Capital of Ecuador?Quito','Capital of Ecuador?',93805795,0,'');
INSERT INTO "notes" VALUES(1476021353212,'s-x)P3;UJ+',1475850444584,1476205337,13,' South_America capitals ','Capital of Peru?Lima<div><br /></div><div><img src="lima-miraflores-rw.jpg" /></div>','Capital of Peru?',1899195448,0,'');
INSERT INTO "notes" VALUES(1476021369814,'p~,SBD&um#',1475850444584,1476205352,13,' South_America capitals ','Capital of Bolivia?La Paz<div><br /></div><div><img src="La_Paz_Skyline.jpg" /></div>','Capital of Bolivia?',2475357406,0,'');
INSERT INTO "notes" VALUES(1476021495601,'h(+l3fJs48',1475850444584,1476205311,13,' South_America capitals ','Capital of Uruguay?Montevideo<div><br /></div><div><img src="montevideo-uruguay.jpg" /></div><div><br /></div><div>[sound:rec1476205311.mp3]</div>','Capital of Uruguay?',3423412928,0,'');
INSERT INTO "notes" VALUES(1476021520017,'g[QWvAO[:]',1475850444584,1476205181,13,' South_America capitals ','Capital of Paraguay?Asuncion<div><br /></div><div><img src="asuncion-paraguay.jpg" /></div><div><br /></div><div>[sound:rec1476205181.mp3]</div>','Capital of Paraguay?',3088135100,0,'');
CREATE INDEX ix_notes_usn on notes (usn);
CREATE INDEX ix_notes_csum on notes (csum);
COMMIT;
sqlite> 

此时您可以自由地使用标准 SQL 命令更新条目。

答案2

在anki手册里有一个帮助,anki卡片是用XML编写的,并且模板有类似的语法 http://ankisrs.net/docs/manual.html#cards-and-templates

导入 Anki 可以导入文本文件、通过导出功能创建的打包 Anki 卡片组、Mnemosyne 2.0 .db 文件和 SuperMemo .xml 文件。要导入文件,请单击文件菜单,然后单击“导入”。

相关内容