Closed tedblizzard closed 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.
python obsidian_to_anki.py -c
to load and open the config file.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.
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
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
C:\Users\tedbl\OneDrive\Documents\B_Brain_V1>
Sorry, I don't know how to handle this error. Maybe @Pseudonium could help!!
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
@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.
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-->
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 :)
@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
@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.
@okerivy The card gets added to Anki but no update in Obsidian.
@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.
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
Ah, this was the famous Unicode error! I've heard about this for a while, glad to know that it's fixed now.
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: