diff --git a/AnkiConnect.py b/AnkiConnect.py index ada4326..605dd21 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -449,11 +449,21 @@ class AnkiConnect: if name in ankiNote: ankiNote[name] = value + allowDuplicate = False + if 'options' in note: + if 'allowDuplicate' in note['options']: + allowDuplicate = note['options']['allowDuplicate'] + if type(allowDuplicate) is not bool: + raise Exception('option parameter \'allowDuplicate\' must be boolean') + duplicateOrEmpty = ankiNote.dupeOrEmpty() if duplicateOrEmpty == 1: raise Exception('cannot create note because it is empty') elif duplicateOrEmpty == 2: + if not allowDuplicate: raise Exception('cannot create note because it is a duplicate') + else: + return ankiNote elif duplicateOrEmpty == False: return ankiNote else: diff --git a/README.md b/README.md index eb77e01..3eabc8e 100644 --- a/README.md +++ b/README.md @@ -685,7 +685,8 @@ guarantee that your application continues to function properly in the future. optional and can be omitted. If you choose to include it, the `url` and `filename` fields must be also defined. The `skipHash` field can be optionally provided to skip the inclusion of downloaded files with an MD5 hash that matches the provided value. This is useful for avoiding the saving of error pages and stub files. The `fields` member is a - list of fields that should play audio when the card is displayed in Anki. + list of fields that should play audio when the card is displayed in Anki. The 'allowDuplicate' member inside 'options' + group can be set to true to enable adding duplicate cards. Normally duplicate cards can not be added and trigger exception. *Sample request*: ```json @@ -700,6 +701,9 @@ guarantee that your application continues to function properly in the future. "Front": "front content", "Back": "back content" }, + "options": { + "allowDuplicate": false + }, "tags": [ "yomichan" ],