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'