ObsidianToAnki / Obsidian_to_Anki

Script to add flashcards from text/markdown files to Anki
GNU General Public License v3.0
1.48k stars 131 forks source link

Processed seems to run successfully but no Anki Cards #80

Closed tedblizzard closed 3 years ago

tedblizzard commented 3 years ago

Everything seemed to work but it did not generate any cards. I copied the text directly from the readme (See Test2.txt).

Is there something I am missing or another place I need to check?
Thank you for your help or guidance.

Please note: Test2.txt renamed for from Test2.md for upload.

Input: Test2.txt

Process: Obsidian_To_Anki_worked_but_NO_Anki_Cards

ddfonseca commented 3 years ago

I can't use the GUI, but I'll explain how I do it in command line.

First, it seems you copy the "ruled" style, right? You need to activate the regex on config and put the regex ruled on the note type you like.

  1. python obsidian_to_anki.py -c to load and open the config file.
  2. If didn't open it with your text editor, open manually the obsidian_to_anki_config.ini file
  3. On the bottom of file, you need change "Regex = False" to "Regex = True"
  4. On [Custom Regexps] you need to copy the regex you want. Since you give me the ruled style, I'll put here. So change "Basic = " to "Basic = ((?:[^\n][\n]?)+\n)-{3,}\n((?:[^\n][\n]?)+)"
  5. Now, python obsidian_to_anki.py PATH_TO_YOUR_FILE.md

If the script runs correctly, it will create an ID on it. See if this helps you.

tedblizzard commented 3 years ago

Thank you so much for your note. I really would like to get this working and appreciate your help.

After making the indicated changes above I get the following errors:

Attempting to connect to Anki... Connected! Loading configuration file... Loaded successfully! Identified target deck for C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\Test2.md as Default Scanning file C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\Test2.md for notes... Getting tag list Adding media with these filenames... [] Adding directory requests... Forming request 1 for directory C:\Users\tedbl\OneDrive\Documents\B_Brain_V1 Adding notes into Anki... Updating fields of existing notes... Getting card IDs of notes to be edited... Removing empty notes... Traceback (most recent call last): File "obsidian_to_anki.py", line 1561, in main() File "obsidian_to_anki.py", line 187, in main App() File "obsidian_to_anki.py", line 913, in init Config.config.write(configfile) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\configparser.py", line 919, in write self._write_section(fp, section, File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\configparser.py", line 932, in _write_section fp.write("{}{}\n".format(key, value)) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u1eef' in position 2: character maps to

tedblizzard commented 3 years ago

Please note: After running above Anki ends up with the card that was in Obsidian However, The Obsidian file does not have the identifier you described above. Also, if I try to re-run the code again I get the following error:

C:\Users\tedbl\OneDrive\Documents\B_Brain_V1>python obsidian_to_anki.py Attempting to connect to Anki... Connected! Loading configuration file... Error: 'utf-8' codec can't decode byte 0x95 in position 5806: invalid start byte Attempting to fix config file... Updating configuration file... Config file exists, reading... Traceback (most recent call last): File "obsidian_to_anki.py", line 830, in init Config.load_config() File "obsidian_to_anki.py", line 756, in load_config config.read(CONFIG_PATH, encoding='utf-8-sig') File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\configparser.py", line 697, in read self._read(fp, filename) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\configparser.py", line 1017, in _read for lineno, line in enumerate(fp, start=1): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\encodings\utf_8_sig.py", line 69, in _buffer_decode return codecs.utf_8_decode(input, errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x95 in position 5806: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "obsidian_to_anki.py", line 1561, in main() File "obsidian_to_anki.py", line 187, in main App() File "obsidian_to_anki.py", line 834, in init Config.update_config() File "obsidian_to_anki.py", line 652, in update_config config.read(CONFIG_PATH, encoding='utf-8-sig') File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\configparser.py", line 697, in read self._read(fp, filename) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\configparser.py", line 1017, in _read for lineno, line in enumerate(fp, start=1): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\encodings\utf_8_sig.py", line 69, in _buffer_decode return codecs.utf_8_decode(input, errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x95 in position 5806: invalid start byte

C:\Users\tedbl\OneDrive\Documents\B_Brain_V1>

ddfonseca commented 3 years ago

Sorry, I don't know how to handle this error. Maybe @Pseudonium could help!!

tedblizzard commented 3 years ago

Oh, I do want to thank you for your help and hope @Pseudonium can give me a hand. This would be a real game-changer for my (and many peoples) workflow. Thank you for your help @ddfonseca

okerivy commented 3 years ago

@tedblizzard

1 Check your python version. It needs to be version 3 and not above 3.9. Preferably 3.8.7 or 3.8.6 , My version is 3.8.3 (Since you can run successfully before, there is no problem at this step. ) (But some people will make mistakes after installing python3.9.)

2 Run the obstoanki_setup.py file first, and the obsidian_to_anki_config.ini file will be generated. (Run it only once to generate this file, and no longer need to run it in the future.)

3 Edit the obsidian_to_anki_config.ini file and Change the line Basic = to Basic = ((?:[^\n][\n]?)+\n)-{3,}\n((?:[^\n][\n]?)+)

Make sure you use utf-8 encoding to paste this code into the file.

4 Run obsidian_to_anki.py, chose the file, check regex box. and run start button.

5, If the card is not created in anki, close the obsidianToanki gui window and run obsidian_to_anki.py again.

okerivy commented 3 years ago
Getting card IDs of notes to be edited...
Removing empty notes...
Traceback (most recent call last):
  File "obsidian_to_anki.py", line 1561, in <module>
    main()
  File "obsidian_to_anki.py", line 187, in main
    App()
  File "obsidian_to_anki.py", line 917, in __init__
    directory.parse_requests_1(AnkiConnect.parse(response), tags)
  File "obsidian_to_anki.py", line 1500, in parse_requests_1
    file.card_ids = AnkiConnect.parse(card_ids)
  File "obsidian_to_anki.py", line 215, in parse
    raise Exception(response['error'])
Exception

Sometimes an error will be reported because of the following reason:

After the card is generated from obsidian through python, an note id will be generated in the obsidian file. if you delete the card in anki, but do not delete the note id in obsidian, if run obsidian_to_anki.py again then an error will be reported because the note for this card id is not found.

Just delete this note id in obsidian. the id like this <!--ID: 1603096166493-->

mifegui commented 3 years ago

I also had the same error:

UnicodeDecodeError: 'utf-8' codec can't decode byte...

On Windows with python 3.8.6

Turns out I couldn't rerun the gui a second time because it converted the (untouched) config file into (in my case) latin1 So I just transformed it back into utf-8

Then it runs fine and... transforms it back into latin1

So I commented some writing stuff to the config file in the code until it stopped doing that and then uncommented to see what line was doing it.

So line 747 looks like this

with open(CONFIG_PATH, "w", encoding='utf-8') as configfile:

and 912 looks like this

with open(CONFIG_PATH, "w") as configfile:

Added the encoding='utf-8' to line 912 and the problem is fixed :)

tedblizzard commented 3 years ago

@okerivy I completed the process as you defined but still seem to be getting this utf-8 problem.

C:\Users\tedbl\OneDrive\Documents\B_Brain_V1>python obsidian_to_anki.py Attempting to connect to Anki... Connected! Loading configuration file... Error: 'utf-8' codec can't decode byte 0x95 in position 2110: invalid start byte Attempting to fix config file... Updating configuration file... Config file exists, reading... Traceback (most recent call last): File "obsidian_to_anki.py", line 830, in init Config.load_config() File "obsidian_to_anki.py", line 756, in load_config config.read(CONFIG_PATH, encoding='utf-8-sig') File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\configparser.py", line 697, in read self._read(fp, filename) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\configparser.py", line 1017, in _read for lineno, line in enumerate(fp, start=1): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\encodings\utf_8_sig.py", line 69, in _buffer_decode return codecs.utf_8_decode(input, errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x95 in position 2110: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "obsidian_to_anki.py", line 1561, in main() File "obsidian_to_anki.py", line 187, in main App() File "obsidian_to_anki.py", line 834, in init Config.update_config() File "obsidian_to_anki.py", line 652, in update_config config.read(CONFIG_PATH, encoding='utf-8-sig') File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\configparser.py", line 697, in read self._read(fp, filename) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\configparser.py", line 1017, in _read for lineno, line in enumerate(fp, start=1): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64qbz5n2kfra8p0\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\encodings\utf_8_sig.py", line 69, in _buffer_decode return codecs.utf_8_decode(input, errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x95 in position 2110: invalid start byte

tedblizzard commented 3 years ago

@okerivy also verified Python version is ok. Note: C:\Users\tedbl\OneDrive\Documents\B_Brain_V1>python Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

tedblizzard commented 3 years ago

@okerivy The card gets added to Anki but no update in Obsidian.

tedblizzard commented 3 years ago

@mifegui and @okerivy Thank you for your help. It is now working.

@mifegui I reset the ini file and updated line 912 as you indicated. image

The program ran with no errors and cards were produced in Anki and updated ID's in Obsidian.

This is a game-changer for me. I currently use RemNote because of the SRS but now I can explore Obsidian. As a Dynalist customer, this is just fantastic. I am so happy.

Thank you for your help.
Ted

Pseudonium commented 3 years ago

Ah, this was the famous Unicode error! I've heard about this for a while, glad to know that it's fixed now.