Help using mn3_anki_fix python3 script : fixing cloze deletion problems on Anki Cards exported by MN3

Hello everyone,

as mentionned here I’m facing some difficulties using a python3 script for fixing cloze deletion problems on Anki Cards exported by MN3 (see : this thread on MN forum). i.e :

expected: {{c1::hello}} my {{c2::world}}
got: {{c1::hello}} my {{c1::world}}

Is there anyone able to help me having my cloze deletion exported correctly from MN3 ?

Here is the problem I’m facing :

When exporting from MN3 with “Mask the Emphasis in text” option off :

The script works fine :

But then the cloze deletion are shown with underline in Anki App :

So I tried exporting from MN3 with “Mask the Emphasis in text” option on :

But then I got this message in terminal :

dhcp-181-29:mn3_anki_fix-master josephdupont$ ./fix_mn_anki_exports.py fix "/Users/josephdupont/Desktop/With.apkg"
[10/21/2021 14:44:17][fix_mn_anki_exports]: files: ['collection.anki2', 'media']
[10/21/2021 14:44:17][fix_mn_anki_exports]: Extracted collection.anki2 to /tmp/mn-anki-exports-fix/tmplljjj4v_
[10/21/2021 14:44:17][fix_mn_anki_exports]: Loaded the model
[10/21/2021 14:44:17][fix_mn_anki_exports]: Loaded 48 notes
[10/21/2021 14:44:17][fix_mn_anki_exports]: Fixed all 48 notes
[10/21/2021 14:44:17][fix_mn_anki_exports]: Loaded deck info: deck name = 20184556082557, id = Droit public - Chapitre 5 : les autorités indépendantes
[10/21/2021 14:44:17][fix_mn_anki_exports]: Generating output file /tmp/output.apkg
Traceback (most recent call last):
  File "/Users/josephdupont/Desktop/mn3_anki_fix-master/./fix_mn_anki_exports.py", line 346, in <module>
    main(obj={})
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/Users/josephdupont/Desktop/mn3_anki_fix-master/./fix_mn_anki_exports.py", line 304, in fix
    _fix_path(path)
  File "/Users/josephdupont/Desktop/mn3_anki_fix-master/./fix_mn_anki_exports.py", line 317, in _fix_path
    _fix_dbfile(dbfile)
  File "/Users/josephdupont/Desktop/mn3_anki_fix-master/./fix_mn_anki_exports.py", line 56, in _fix_dbfile
    return _fix_db(db)
  File "/Users/josephdupont/Desktop/mn3_anki_fix-master/./fix_mn_anki_exports.py", line 284, in _fix_db
    genanki.Package(deck).write_to_file(OUTPUT_FILE)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/genanki/package.py", line 29, in write_to_file
    self.write_to_db(cursor, now_ts)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/genanki/package.py", line 49, in write_to_db
    deck.write_to_db(cursor, now_ts)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/genanki/deck.py", line 67, in write_to_db
    note.write_to_db(cursor, now_ts, self.deck_id)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/genanki/note.py", line 69, in write_to_db
    card.write_to_db(cursor, now_ts, deck_id, note_id)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/genanki/card.py", line 9, in write_to_db
    cursor.execute('INSERT INTO cards VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);', (
sqlite3.IntegrityError: UNIQUE constraint failed: cards.id
dhcp-181-29:mn3_anki_fix-master josephdupont$ 

What did I do wrong ?..

Best regards,
Joseph