GithubHelp home page GithubHelp logo

mn3_anki_fix's Introduction

This tools may no longer work with the latest version of MarginNote.

This tool was written several years ago, and most likely the format of the apkg file exported by MN has been changed so far.

What is this

Fix the anki cards exported by MarginNote3 (up to 3.4.3). The problems I suffer are:

  • Only one anki card is generated, even if there are multiple clozes.
  • Inconsistent & confusing format of the card front / back for cards w/ clozes in the title and cards w/o.
  • MN tags appear in the back of the anki card.

This script reads the contents of generated apkg file, and makes use of genanki package to rewrite it to a better one.

Visual Comparison

Original apkg imported into Anki

  • title shown in bottom
  • only one card for 3 clozes
  • tag is shown in the back card

Improved apkg imported into Anki

Limitations

  1. All existing MN3 anki cards must be deleted from anki first. Otherwise the import would fail.
  2. Cards with images/videos/audios are not supported.

How to use

  1. Make sure python3 is installed on your Mac.
  2. Install the requirements
    pip3 install -r requirements.txt
  1. Run the script to fix the exported apkg file before importing them to anki.
./fix_mn_anki_exports.py fix /path/to/apkg

You'll see output like this:

[09/14/2019 23:00:47][fix_mn_anki_exports]: Auto located apkg file /path/to/apkg
[09/14/2019 23:00:47][fix_mn_anki_exports]: files: ['collection.anki2', 'media']
[09/14/2019 23:00:47][fix_mn_anki_exports]: Extracted collection.anki2 to /tmp/mn-anki-exports-fix/tmprjqntj9e
[09/14/2019 23:00:47][fix_mn_anki_exports]: Loaded the model
[09/14/2019 23:00:47][fix_mn_anki_exports]: Loaded 45 notes
[09/14/2019 23:00:47][fix_mn_anki_exports]: Fixed all 45 notes
[09/14/2019 23:00:47][fix_mn_anki_exports]: Loaded deck info: deck name = 20181501542376, id = mydeck
[09/14/2019 23:00:47][fix_mn_anki_exports]: Generating output file /tmp/output.apkg

The improved apkg would be /tmp/output.apkg.

mn3_anki_fix's People

Contributors

lins05 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

loiks

mn3_anki_fix's Issues

Stuck at step 3

Dear, Lins05.

Thank you very much for this script. I'm stuck at step 3 :

  1. Run the script to fix the exported apkg file before importing them to anki.
    ./fix_mn_anki_exports.py fix /path/to/apkg

I managed to install and run python but I don't know the process to run the script and/or indicate the correct path to Apkg.

Here is what I did :

  1. Installed Python, when I run $ python3
    I got :
Python 3.10.0 (v3.10.0:b494f5935c, Oct  4 2021, 14:59:20) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
  1. Exported my flashcards from MN to this path :
    /Users/josephdupont/Desktop/Droit public.apkg

  2. So now I'm stuck. Here is what I get when I run the script ./fix_mn_anki_exports.py fix /path/to/apkg (after running python3 in terminal) :

>>> ./fix_mn_anki_exports.py fix /Users/josephdupont/Desktop/Droit public.apkg
  File "<stdin>", line 1
    ./fix_mn_anki_exports.py fix /Users/josephdupont/Desktop/Droit public.apkg
    ^
SyntaxError: invalid syntax
>>> 

May I ask you to please help me (and save my exams at the same time ?..)

Thank you very much for your hard work fixing MN issues.
Best regards,
Joseph

【Solved】Can't work when decks include Chinese

It's an amazing script. But I meet a big problem, when my decks include Chinese words. It doesn't work.

OS: Windows 10
Python 3.8.1

Here are how I found:

"1.apkg" does not contain Chinese and "2.apkg" contains.

Output on cmd:
D:\mn3_anki_fix-master>fix_mn_anki_exports.py fix 1.apkg
[01/12/2020 00:03:46][fix_mn_anki_exports]: files: ['collection.anki2', 'media']
[01/12/2020 00:03:46][fix_mn_anki_exports]: Extracted collection.anki2 to tmp/mn-anki-exports-fix\tmpf6x_yqa0
[01/12/2020 00:03:46][fix_mn_anki_exports]: Loaded the model
[01/12/2020 00:03:46][fix_mn_anki_exports]: Loaded 3 notes
[01/12/2020 00:03:46][fix_mn_anki_exports]: Fixed all 3 notes
[01/12/2020 00:03:46][fix_mn_anki_exports]: Loaded deck info: deck name = 20183894427430, id = testdeck
[01/12/2020 00:03:46][fix_mn_anki_exports]: Generating output file tmp/output.apkg

D:\mn3_anki_fix-master>fix_mn_anki_exports.py fix 2.apkg
[01/12/2020 00:03:54][fix_mn_anki_exports]: files: ['collection.anki2', 'media']
[01/12/2020 00:03:54][fix_mn_anki_exports]: Extracted collection.anki2 to tmp/mn-anki-exports-fix\tmpy50idcuf
[01/12/2020 00:03:54][fix_mn_anki_exports]: Loaded the model
[01/12/2020 00:03:54][fix_mn_anki_exports]: Loaded 17 notes
Traceback (most recent call last):
File "D:\mn3_anki_fix-master\fix_mn_anki_exports.py", line 317, in _fix_path
_fix_dbfile(dbfile)
File "D:\mn3_anki_fix-master\fix_mn_anki_exports.py", line 56, in _fix_dbfile
return _fix_db(db)
File "D:\mn3_anki_fix-master\fix_mn_anki_exports.py", line 275, in _fix_db
fixed_notes = [_fix_note(db, cloze_model, non_cloze_model, note) for note in notes]
File "D:\mn3_anki_fix-master\fix_mn_anki_exports.py", line 275, in
fixed_notes = [_fix_note(db, cloze_model, non_cloze_model, note) for note in notes]
File "D:\mn3_anki_fix-master\fix_mn_anki_exports.py", line 250, in _fix_note
if is_empty_field(fields['ClozeFront']):
KeyError: 'ClozeFront'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 607, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'tmp/mn-anki-exports-fix\tmpy50idcuf\collection.anki2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 804, in onerror
_os.unlink(path)
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'tmp/mn-anki-exports-fix\tmpy50idcuf\collection.anki2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\mn3_anki_fix-master\fix_mn_anki_exports.py", line 346, in
main(obj={})
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\site-packages\click\core.py", line 764, in call
return self.main(*args, **kwargs)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\site-packages\click\core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\site-packages\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "D:\mn3_anki_fix-master\fix_mn_anki_exports.py", line 304, in fix
_fix_path(path)
File "D:\mn3_anki_fix-master\fix_mn_anki_exports.py", line 317, in _fix_path
_fix_dbfile(dbfile)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 829, in exit
self.cleanup()
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 833, in cleanup
self._rmtree(self.name)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 815, in _rmtree
_shutil.rmtree(name, onerror=onerror)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 731, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 609, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 807, in onerror
cls._rmtree(path)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 815, in _rmtree
_shutil.rmtree(name, onerror=onerror)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 731, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 590, in _rmtree_unsafe
onerror(os.scandir, path, sys.exc_info())
File "C:\Users\z233\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 587, in _rmtree_unsafe
with os.scandir(path) as scandir_it:
NotADirectoryError: [WinError 267] 目录名称无效。: 'tmp/mn-anki-exports-fix\tmpy50idcuf\collection.anki2'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.