obsidiantoanki / obsidian_to_anki Goto Github PK
View Code? Open in Web Editor NEWScript to add flashcards from text/markdown files to Anki
License: GNU General Public License v3.0
Script to add flashcards from text/markdown files to Anki
License: GNU General Public License v3.0
I open Anki and run the script and it works well. If I try to run it again, it keeps stuck at "Removing Empty notes..."
The only way to run it again is to close the script, close Anki and start them again
More clarification on how fields should be inputted by default would be really helpful. For example, I was struggling with managing multiple optional fields. E.g., if Field 2, Field 3, Field 4 are optional, then
START
Note Type
[Field 1 Content]
Field 3: [Field 3 Content]
END
is invalid syntax. Instead, you must write
START
Note Type
[Field 1 Content]
Field 2:
Field 3: [Field 3 Content]
END
In other words, optional fields can be omitted at the end, but not in-between. Either this should be clarified in the Documentation, or change the default behavior. It should also be clarified that you CANNOT explicitly write
START
Note Type
Field 1: [Field 1 Content]
END
This becomes problematic if Field 1 is optional-- a note of this form:
START
Note Type
Field 1:
Field 2: [Field 2 Content]
END
is not possible (maybe by leaving a blank line? This seems unintended, though).
Hey there! I am new to programming and would like a beginner's version of running this program. I use a Mac. I have downloaded the latest python shell and am comfortable running python scripts from terminal (python3 filename.py) I have downloaded anki connect, but I would love to learn how to run this code.
When I run obstoanki.py, I get an SSL certificate issuer error.
Currently the markup files are processed randomly. The problem with this approach is the order in which cards are inserted into anki is the order in which they are reviewed. If someone wants a certain order (study material progresses through chapters...) that is a problem.
I request at least for an option that process markup files in order that humans call natural.
Now:
1.txt
9.txt
7.txt
2.txt
Requested:
1.txt
2.txt
7.txt
9.txt
Hey,
When I try to run the obstoanki_setup.py, I'm getting this error:
ERROR: Command errored out with exit status 1:
command: 'C:\Users\Gab\AppData\Local\Programs\Python\Python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Gab\\AppData\\Local\\Temp\\pip-install-hr1d5j6a\\wxpython\\setup.py'"'"'; __file__='"'"'C:\\Users\\Gab\\AppData\\Local\\Temp\\pip-install-hr1d5j6a\\wxpython\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Gab\AppData\Local\Temp\pip-record-rbfq_8m1\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Gab\AppData\Local\Programs\Python\Python39\Include\wxpython'
cwd: C:\Users\Gab\AppData\Local\Temp\pip-install-hr1d5j6a\wxpython\
Complete output (27 lines):
running install
running build
Will build using: "C:\Users\Gab\AppData\Local\Programs\Python\Python39\python.exe"
3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
Python's architecture is 64bit
cfg.VERSION: 4.0.7
Running command: build
Running command: build_wx
Command '"C:\Users\Gab\AppData\Local\Programs\Python\Python39\python.exe" -c "import distutils.msvc9compiler as msvc; mc = msvc.MSVCCompiler(); mc.initialize(); print(mc.cc)"' failed with exit code 1.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Gab\AppData\Local\Programs\Python\Python39\lib\distutils\msvc9compiler.py", line 371, in initialize
vc_env = query_vcvarsall(VERSION, plat_spec)
File "C:\Users\Gab\AppData\Local\Programs\Python\Python39\lib\distutils\msvc9compiler.py", line 260, in query_vcvarsall
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
distutils.errors.DistutilsPlatformError: Unable to find vcvarsall.bat
Finished command: build_wx (0.78s)
Finished command: build (0.78s)
WARNING: Building this way assumes that all generated files have been
generated already. If that is not the case then use build.py directly
to generate the source and perform the build stage. You can use
--skip-build with the bdist_* or install commands to avoid this
message and the wxWidgets and Phoenix build steps in the future.
"C:\Users\Gab\AppData\Local\Programs\Python\Python39\python.exe" -u build.py build
Command '"C:\Users\Gab\AppData\Local\Programs\Python\Python39\python.exe" -u build.py build' failed with exit code 1.
----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\Gab\AppData\Local\Programs\Python\Python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Gab\\AppData\\Local\\Temp\\pip-install-hr1d5j6a\\wxpython\\setup.py'"'"'; __file__='"'"'C:\\Users\\Gab\\AppData\\Local\\Temp\\pip-install-hr1d5j6a\\wxpython\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Gab\AppData\Local\Temp\pip-record-rbfq_8m1\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Gab\AppData\Local\Programs\Python\Python39\Include\wxpython' Check the logs for full command output.
What can I do?
Windows 10 64bits Pro Version
Python 3.9
Pip 20.2.4
This is happening when I try to run the script. I don't know if this is a error from the script or AnkiConnect
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 1505, in parse_requests_1
file.get_cards()
File "obsidian_to_anki.py", line 1261, in get_cards
self.cards += info["cards"]
KeyError: 'cards'
Sometimes the script doesn't crash, but it stays stuck forever
Hi, it work well for this type:
Q: question
A: answer
but if i changed like this, it have problem:
Q: question
A:
answer
Kindly help how to custom syntax to make the second type work.
I ended up generating 6k+ text files for 6k+ cards (1:1).
It is because a text file can contain only one set of tags: File Tags Line - The string that signals "the line beneath me is the set of tags that should be added to all notes from this file". Defaults to FILE TAGS.
. Otherwise only ~300 text files needed to be generated.
Please improve upon the syntax so the tags apply to a set of cards in the same file.
Eg:
TARGET DECK
DECK1
FILE TAGS
tag1 tag2
START
note-1
val1
f2: val2
END
FILE TAGS
tag1 tag3
START
note-2
val3
f2: val4
END
START
note-2
val5
f2: val6
END
Also the script kind of stopped for a long time* at Replacing tags...
. I wonder if it is due to the huge number of files.
It is still running for almost an hour. Started at 00:13 and now it is 00:55. (I can't exactly tell when it stopped but it stopped before 01:01)
I get the following error when trying to make note from a paragraph which is succeeded by a transcluded content.
PLease see if can be fixed :)
PS Thnks for the script! :)
PageName%20WordAfterASpace%20WordAfterASpace%20(1967)#%5Eae427e
Traceback (most recent call last):
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 1561, in <module>
main()
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 187, in main
App()
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 872, in __init__
Directory(root, regex=args.regex)
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 1441, in __init__
file.scan_file()
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 1311, in scan_file
self.search(note_type, regexp)
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 1372, in search
parsed = RegexNote(match, note_type, tags=False, id=False).parse(
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 625, in parse
template["fields"] = self.fields
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 609, in fields
fields = {
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 610, in <dictcomp>
key: FormatConverter.format(
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 395, in format
FormatConverter.get_images(note_text)
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 328, in get_images
MEDIA[filename] = file_encode(path)
File "C:\Users\DummyMe\Desktop\Obsidian_to_Anki-2.9.0\obsidian_to_anki.py", line 104, in file_encode
with open(filepath, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'PageName%20WordAfterASpace%20WordAfterASpace%20(1967)#%5Eae427e'
Hi,
I get the following error in the GUI when attempting to add an Obsidian .md file to Anki. I am attaching the .md file to this issue.
Attempting to connect to Anki...
Connected!
Loading configuration file...
Loaded successfully!
Identified target deck for Vocabulary.md as Default
Scanning file Vocabulary.md for notes...
Getting tag list
Adding media with these filenames...
[]
Adding directory requests...
Forming request 1 for directory C:\Users\ShaunakAgarkhedkar\OneDrive\Japanese Notes\Obsidian Notes\日本語
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:\Users\ShaunakAgarkhedkar\Anaconda3\lib\configparser.py", line 918, in write
self._sections[section].items(), d)
File "C:\Users\ShaunakAgarkhedkar\Anaconda3\lib\configparser.py", line 922, in _write_section
fp.write("[{}]\n".format(section_name))
File "C:\Users\ShaunakAgarkhedkar\Anaconda3\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-7: character maps to
Please advise if there's anything I can do to fix this.
Really appreciate your efforts, and thank you for creating this script.
Regards,
Shaunak
Vocabulary.zip
would be helpful to see some simple/slightly complex examples of markdown syntax --> card displayed in pictures as well as written out :)
with #13 that might help if some have a less stupid implementation of python on their system, i used brew on mac to install it and so the shebang causes issues with that, but it would still be a great addition to portably let people just execute it. For FAQ or installation instructions you could also say that if you hit errors like i did, to just explicitly run python3 <path to script>
compared to current readme:
From the command line, run the script once with no arguments - {Path to script}/obsidian_to_anki.py This will make a configuration file in the same directory as the script, "obsidian_to_anki_config.ini".
just a thought ^_^
When I paste an image in Obsidian, the image doesn't show up in Anki. Only the wiki image link does ("![[image.jpg]]").
Tried using images from internet (copy-paste and drag-and-drop), and local images.
Pasted image in Obsidian (Edit mode)
Pasted image in Obsidian (Preview mode), the image shows up
Pasted image not showing up in Anki (during review)
Pasted image not showing up in Anki (in the browser)
On Windows 10 Pro 1903
Using Python 3.7.0 (because the script crashes with older versions because of dependency problems)
Using the remnote syntax + custom syntax [3 colons = Basic (and reversed)] (tested with the proposed syntax, doesn't work either)
Instead of the default behavior which uses 2 lines
FILE TAGS
Math Physics
Is there a way to put the File Tags in just one line? like this
FILE TAGS: Math Physics
I am leaving this here for future reference and for others running into issues whilst trying to install Obsidian_to_Anki
on Ubuntu 20.04
.
The issues were:
The Ubuntu 20.04 distro now comes with python3 (3.8.5), however pip3 is missing. Install:
sudo apt update
sudo apt install -y python3-pip
Thenm, to solve the wxpython install error:
sudo apt install -y libgtk-3-dev python-wxgtk3.0
[Optional ] The above should suffice. If you still receive an error during install of wxpython
it may be necessary to install the following dependencies below as well. Be sure to check the error logs.
sudo apt install -y python3-wxgtk4.0 python3-wxgtk-webview4.0 python3-wxgtk-media4.0
Running the install script should now finish succesfully:
python3 obstoanki_setup.py
Error Message
Traceback (most recent call last):
File "C:\Users\Leon\OneDrive\_ApplicationData\ObsdianLibrary\.addon\obsidian_to_anki.py", line 1561, in <module>
main()
File "C:\Users\Leon\OneDrive\_ApplicationData\ObsdianLibrary\.addon\obsidian_to_anki.py", line 187, in main
App()
File "C:\Users\Leon\OneDrive\_ApplicationData\ObsdianLibrary\.addon\obsidian_to_anki.py", line 917, in __init__
directory.parse_requests_1(AnkiConnect.parse(response), tags)
File "C:\Users\Leon\OneDrive\_ApplicationData\ObsdianLibrary\.addon\obsidian_to_anki.py", line 1500, in parse_requests_1
file.card_ids = AnkiConnect.parse(card_ids)
File "C:\Users\Leon\OneDrive\_ApplicationData\ObsdianLibrary\.addon\obsidian_to_anki.py", line 215, in parse
raise Exception(response['error'])
Exception
The regex guide says:
You need to have as many capture groups in your regexp as there are fields in the note type - the 1st capture group becomes the 1st field, the 2nd becomes the 2nd field etc
If I have more than 1 capture group in the custom regex set in the config file, it only adds the first one to the card. The other capture groups aren't added to the card.
My default Cloze note type has 3 fields.
It's me again 👍
I use CurlyCloze with custom regex without problem, on config I put:
Cloze = ^T: ((?:[^\n][\n]?)+)\n+E: ((?:[^\n][\n]?)+)
And
CurlyCloze = True
So if I have a note like this:
T: My name is {David}.
E: (nothing)
Works fine!
But now I tried to put with Cloze Hide All and didn't work. Config for Cloze Hide All:
Cloze (Hide all) = ^T: ((?:[^\n][\n]?)+)\n+E: ((?:[^\n][\n]?)+)\n+H: ((?:[^\n][\n]?)+)
Then, if I have a note like this:
T: First question?
{Answer1}
Second question?
{Answer2}
Third question?
{Answer3}
E: (nothing)
H: yes
I expected the script to create a cloze hide all note with {{c1::}}, {{c2::}} and {{c3::}}, but only translate to {Answer1} {Answer2}, without even with {Answer3} (I don't know why).
So, is it possible to use CurlyCloze with other type of note beyond Cloze?
Thanks
How do you open a .ini file on mac to edit regex settings?
Remnote can create cards not only single-line cards denoted with a double colon ::
but also multi-line cards with a triple colon :::
and list cards ::1
.
Support for this will be useful for those that structure their Obsidian notes using Remnote syntax with the ability to export to both Anki and Remnote if the situation arises.
See: https://www.remnote.io/documentation/DbrajFGebhyrKHGYA for more info.
This isn't an issue, this is an announcement, as @Pseudonium wrote that some features were to be delayed until an official API was available.
API available here, announced in the 0.9.7 release.
It'd be great if you could include that, as they're doing here: https://github.com/kangruixiang/Ankify
I am using your Q/A and cloze regex, I would like a small alteration.
I want a card to end whenever there is a double line break (in both the cases).
Q: This is a Question
A: This is Answer Line 1
This is Answer line 2.
This is Answer line 3
This is not in answer.
Similarly, for cloze cards, the card will end whenever there is a double line break.
Is it possible? :)
Hi, I am having difficulty running the install script. The system is Win10 x64 build 2004 with Python 3.9.0 installed.
The output from the obstoanki_setup.py is below:
Hi, I am having difficulty running the install script. The system is Win10 x64 build 2004 with Python 3.9.0 installed.
The output from the obstoanki_setup.py is below:
PS C:\temp\ObstoAnki> .\obstoanki_setup.py
Collecting Gooey==1.0.4.0.0.0
Using cached Gooey-1.0.4.0.0.0-py2.py3-none-any.whl (617 kB)
Collecting Markdown==3.2.2
Using cached Markdown-3.2.2-py3-none-any.whl (88 kB)
Requirement already satisfied: Pillow>=4.3.0 in c:\users\someusername\appdata\local\programs\python\python39\lib\site-packages (from Gooey==1.0.4.0.0.0->-r obstoankirequire.txt (line 1)) (8.0.1)
Requirement already satisfied: psutil>=5.4.2 in c:\users\someusername\appdata\local\programs\python\python39\lib\site-packages (from Gooey==1.0.4.0.0.0->-r obstoankirequire.txt (line 1)) (5.7.3)
Requirement already satisfied: colored>=1.3.93 in c:\users\someusername\appdata\local\programs\python\python39\lib\site-packages (from Gooey==1.0.4.0.0.0->-r obstoankirequire.txt (line 1)) (1.4.2)
Collecting wxpython==4.0.7
Using cached wxPython-4.0.7.tar.gz (68.9 MB)
Requirement already satisfied: six in c:\users\someusername\appdata\local\programs\python\python39\lib\site-packages (from wxpython==4.0.7->Gooey==1.0.4.0.0.0->-r obstoankirequire.txt (line 1)) (1.15.0)
Requirement already satisfied: numpy in c:\users\someusername\appdata\local\programs\python\python39\lib\site-packages (from wxpython==4.0.7->Gooey==1.0.4.0.0.0->-r obstoankirequire.txt (line 1)) (1.19.4)
Using legacy 'setup.py install' for wxpython, since package 'wheel' is not installed.
Installing collected packages: wxpython, Gooey, Markdown
Running setup.py install for wxpython ... error
ERROR: Command errored out with exit status 1:
command: 'C:\Users\someusername\AppData\Local\Programs\Python\Python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\someusername\\AppData\\Local\\Temp\\pip-install-qalobcx9\\wxpython\\setup.py'"'"'; __file__='"'"'C:\\Users\\someusername\\AppData\\Local\\Temp\\pip-install-qalobcx9\\wxpython\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\someusername\AppData\Local\Temp\pip-record-p3cg07wl\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\someusername\AppData\Local\Programs\Python\Python39\Include\wxpython'
cwd: C:\Users\someusername\AppData\Local\Temp\pip-install-qalobcx9\wxpython\
Complete output (27 lines):
running install
running build
Will build using: "C:\Users\someusername\AppData\Local\Programs\Python\Python39\python.exe"
3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
Python's architecture is 64bit
cfg.VERSION: 4.0.7
Running command: build
Running command: build_wx
Command '"C:\Users\someusername\AppData\Local\Programs\Python\Python39\python.exe" -c "import distutils.msvc9compiler as msvc; mc = msvc.MSVCCompiler(); mc.initialize(); print(mc.cc)"' failed with exit code 1.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\someusername\AppData\Local\Programs\Python\Python39\lib\distutils\msvc9compiler.py", line 371, in initialize
vc_env = query_vcvarsall(VERSION, plat_spec)
File "C:\Users\someusername\AppData\Local\Programs\Python\Python39\lib\distutils\msvc9compiler.py", line 260, in query_vcvarsall
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
distutils.errors.DistutilsPlatformError: Unable to find vcvarsall.bat
Finished command: build_wx (0.61s)
Finished command: build (0.61s)
WARNING: Building this way assumes that all generated files have been
generated already. If that is not the case then use build.py directly
to generate the source and perform the build stage. You can use
--skip-build with the bdist_* or install commands to avoid this
message and the wxWidgets and Phoenix build steps in the future.
"C:\Users\someusername\AppData\Local\Programs\Python\Python39\python.exe" -u build.py build
Command '"C:\Users\someusername\AppData\Local\Programs\Python\Python39\python.exe" -u build.py build' failed with exit code 1.
----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\someusername\AppData\Local\Programs\Python\Python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\someusername\\AppData\\Local\\Temp\\pip-install-qalobcx9\\wxpython\\setup.py'"'"'; __file__='"'"'C:\\Users\\someusername\\AppData\\Local\\Temp\\pip-install-qalobcx9\\wxpython\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\someusername\AppData\Local\Temp\pip-record-p3cg07wl\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\someusername\AppData\Local\Programs\Python\Python39\Include\wxpython' Check the logs for full command output.
WARNING: You are using pip version 20.2.3; however, version 20.2.4 is available.
You should consider upgrading via the 'C:\Users\someusername\AppData\Local\Programs\Python\Python39\python.exe -m pip install --upgrade pip' command.
Traceback (most recent call last):
File "C:\temp\ObstoAnki\obstoanki_setup.py", line 27, in <module>
subprocess.check_call(
File "C:\Users\someusername\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['C:\\Users\\someusername\\AppData\\Local\\Programs\\Python\\Python39\\python.exe', '-m', 'pip', 'install', '-r', 'obstoankirequire.txt']' returned non-zero exit status 1.
PS C:\temp\ObstoAnki> Get-WindowsVersion
Any help would be appreciated.
Example Markdown:
TARGET DECK
Vocab Deck
FILE TAGS
cefr-level:B2
START
clozenew
absorb
definition:<div class=defBox><div class=posDiv><span>verb</span></div><div class=defDiv><div class=defTextInfo></div><div class=defText>{{c1::If something absorbs a liquid, gas, or other substance, it soaks it up or takes it in.}}</div><div class=defEgText><div>Plants absorb carbon dioxide from the air and moisture from the soil.</div><div>Refined sugars are absorbed into the bloodstream very quickly.</div></div></div></div>
inflections:<span>absorbs</span><span>absorbing</span><span>absorbed</span>
cefr-level:B2
example-bank:
IPA:
END
Now all the field values after "inflections" are being inserted into the "inflections" field itself. Fields after "inflections" remain empty.
Not sure if this is more user error rather than an issue but if there are any spaces after TARGET DECK or FILE TAGS then Obsidian_to_Anki ignores the line, e.g.
TARGET DECK
Test
would not be recognised by the script as there is a space after the word 'DECK'.
Note: copy & pasting from the readme example in my browser resulted in spaces after TARGET DECK being included.
When using tags and the custom regex option the ID is getting appended to the end of the tag. Following regex Q&A example with an input file like:
Q: How do you use this style?
A: Just like this. Tags: #ObsidianTest
Q: Can the question
run over multiple lines?
A: Yes, and
So can the answer Tags: #ObsidianTest
is resulting in
Q: How do you use this style?
A: Just like this. Tags: #ObsidianTestID: 1599656251691
Q: Can the question
run over multiple lines?
A: Yes, and
So can the answer Tags: #ObsidianTestID: 1599656251710
Attempting to connect to Anki...
Connected!
Loading configuration file...
Loaded successfully!
Identified target deck for .\202009152153 1K411011 城镇道路分类与分级.md as Default
Identified target deck for .\202009152220 城镇道路分级.md as Default
Identified target deck for .\202009152221 柔性路面的破坏取决于.md as Default
Identified target deck for .\202009152223 刚性路面的破坏取决于.md as Default
Scanning file .\202009152153 1K411011 城镇道路分类与分级.md for notes...
Scanning file .\202009152220 城镇道路分级.md for notes...
Scanning file .\202009152221 柔性路面的破坏取决于.md for notes...
Scanning file .\202009152223 刚性路面的破坏取决于.md for notes...
Getting tag list
Adding media with these filenames...
[]
Adding directory requests...
Forming request 1 for directory E:_Nutstore\我的坚果云_2020OBLibrary\《1K400000 市政公用工程管理与实务》\1K410000 市政公用技术\1K411000 城镇道路工程\1K411010 城镇道路工程结构与材料\1K411011 城镇道路分类与分级
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 "E:_Nutstore\我的坚果云_2020OBLibrary\Obsidian_to_Anki-master\obsidian_to_anki.py", line 1493, in
main()
File "E:_Nutstore\我的坚果云_2020OBLibrary\Obsidian_to_Anki-master\obsidian_to_anki.py", line 183, in main
App()
File "E:_Nutstore\我的坚果云_2020OBLibrary\Obsidian_to_Anki-master\obsidian_to_anki.py", line 868, in init
directory.parse_requests_1(AnkiConnect.parse(response), tags)
File "E:_Nutstore\我的坚果云_2020OBLibrary\Obsidian_to_Anki-master\obsidian_to_anki.py", line 1432, in parse_requests_1
file.card_ids = AnkiConnect.parse(card_ids)
File "E:_Nutstore\我的坚果云_2020OBLibrary\Obsidian_to_Anki-master\obsidian_to_anki.py", line 211, in parse
raise Exception(response['error'])
Exception
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
Hey,
i found out that your script is running into problems, when facing against some special unicodes. For Example Emojis.
I got this issue fixed by adding a different encoding in your open(file) methods.
open(self.filename, encoding='latin_1')
You can find a list of all encodings here: https://docs.python.org/2.4/lib/standard-encodings.html
I tried writing a test file:
TARGET DECK
Default
START
Basic
Front: Who declares Globally Important Agricultural Heritage Systems?
Back: FAO
Food and Agriculture Organisation
Tags: Economics::Sectors::Agriculture
END
Ran the Obsidian_to_Anki.py script. The script runs "successfully". I get no cards in the ANKI. What am I doing wrong?
(ANKIConnect was working)
Edit: Tried running on your test.md too. Didnt work. There must be something I am missing. :/
Doesn't work for me at all!
Here are the steps I followed:
Here is what I tried via the terminal; please advise:
Peters-MacBook-Air:~ peter$ defaults write net.ankiweb.dtop NSAppSleepDisabled -bool true
Peters-MacBook-Air:~ peter$ defaults write net.ichi2.anki NSAppSleepDisabled -bool true
Peters-MacBook-Air:~ peter$ defaults write org.qt-project.Qt.QtWebEngineCore NSAppSleepDisabled -bool true
Peters-MacBook-Air:~ peter$ /Volumes/NO\ NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 1: Sc: command not foundds to Anki from Obsidian.
: command not foundripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 2:
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 3: import: command not found
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 4: import: command not found
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 5: import: command not found
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 6: import: command not found
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 7: import: command not found
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 8: import: command not found
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 9: import: command not found
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 10: import: command not found
: command not foundripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 11:
: command not foundripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 12:
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 13: syntax error near unexpected token `('
/Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/obsidian_to_anki.py: line 13: `'ef write_safe(filename, contents):
Peters-MacBook-Air:~ peter$ cd /Volumes/NO NAME/Scripts/Obsidian_to_Anki-master/
-bash: cd: /Volumes/NO: No such file or directory
Peters-MacBook-Air:~ peter$ cd /Volumes/NO\ NAME/Scripts/Obsidian_to_Anki-master/
Peters-MacBook-Air:Obsidian_to_Anki-master peter$ ./obsidian_to_anki.py
: command not foundpy: line 1: Script for adding cards to Anki from Obsidian.
: command not foundpy: line 2:
./obsidian_to_anki.py: line 3: import: command not found
./obsidian_to_anki.py: line 4: import: command not found
./obsidian_to_anki.py: line 5: import: command not found
./obsidian_to_anki.py: line 6: import: command not found
./obsidian_to_anki.py: line 7: import: command not found
./obsidian_to_anki.py: line 8: import: command not found
./obsidian_to_anki.py: line 9: import: command not found
./obsidian_to_anki.py: line 10: import: command not found
: command not foundpy: line 11:
: command not foundpy: line 12:
./obsidian_to_anki.py: line 13: syntax error near unexpected token `('
'/obsidian_to_anki.py: line 13: `def write_safe(filename, contents):
Hi, I don't If I'm doing this correctly, so in my config I put this:
[Obsidian]
Vault name = Obsidian
Add file link = True
Obsidian is the name of my Vault on $HOME/Documents/, should I put the whole path?
Then it creates a link on Anki, but I couldn't open it:
Another question, is it possible to add an ID on this link that we could change the CSS style from the cards (not important, by the way)? But a linebreak before insert it would be nice too.
Thanks
i have python 3.8
i have the markdown module installed
brand new Macbook Pro running catalina 10.15.6
i updated imageMagick just in case, no dice
the script was run and i got my config file and everything setup
I troubleshot as much as possible, i have no idea why its not functioning. it should be ಠ_ಠ
running the script in the following ways throws the same error:
~/.local/bin/obsidian_to_anki.py -f c393.md
# OR LIKE THIS
obsidian_to_anki.py -f c393.md
Version: ImageMagick 7.0.10-28 Q16 x86_64 2020-08-16 https://imagemagick.org Copyright: © 1999-2020 ImageMagick Studio LLC License: https://imagemagick.org/script/license.php Features: Cipher DPC HDRI Modules OpenMP(3.1) Delegates (built-in): bzlib freetype gslib heic jng jp2 jpeg lcms lqr ltdl lzma openexr png ps tiff webp xml zlib Usage: import [options ...] [ file ]Image Settings:
-adjoin join images into a single multi-image file
-border include window border in the output image
-channel type apply option to select image channels
-colorspace type alternate image colorspace
-comment string annotate image with comment
-compress type type of pixel compression when writing the image
-define format:option
define one or more image format options
-density geometry horizontal and vertical density of the image
-depth value image depth
-descend obtain image by descending window hierarchy
-display server X server to contact
-dispose method layer disposal method
-dither method apply error diffusion to image
-delay value display the next image after pausing
-encipher filename convert plain pixels to cipher pixels
-endian type endianness (MSB or LSB) of the image
-encoding type text encoding type
-filter type use this filter when resizing an image
-format "string" output formatted image characteristics
-frame include window manager frame
-gravity direction which direction to gravitate towards
-identify identify the format and characteristics of the image
-interlace type None, Line, Plane, or Partition
-interpolate method pixel color interpolation method
-label string assign a label to an image
-limit type value Area, Disk, Map, or Memory resource limit
-monitor monitor progress
-page geometry size and location of an image canvas
-pause seconds seconds delay between snapshots
-pointsize value font point size
-quality value JPEG/MIFF/PNG compression level
-quiet suppress all warning messages
-regard-warnings pay attention to warning messages
-repage geometry size and location of an image canvas
-respect-parentheses settings remain in effect until parenthesis boundary
-sampling-factor geometry
horizontal and vertical sampling factor
-scene value image scene number
-screen select image from root window
-seed value seed a new sequence of pseudo-random numbers
-set property value set an image property
-silent operate silently, i.e. don't ring any bells
-snaps value number of screen snapshots
-support factor resize support: > 1.0 is blurry, < 1.0 is sharp
-synchronize synchronize image to storage device
-taint declare the image as modified
-transparent-color color
transparent color
-treedepth value color tree depth
-verbose print detailed information about the image
-virtual-pixel method
Constant, Edge, Mirror, or Tile
-window id select window with this id or name
root selects whole screenImage Operators:
-annotate geometry text
annotate the image with text
-colors value preferred number of colors in the image
-crop geometry preferred size and location of the cropped image
-encipher filename convert plain pixels to cipher pixels
-geometry geometry preferred size or location of the image
-help print program options
-monochrome transform image to black and white
-negate replace every pixel with its complementary color
-quantize colorspace reduce colors in this colorspace
-resize geometry resize the image
-rotate degrees apply Paeth rotation to the image
-strip strip image of all profiles and comments
-thumbnail geometry create a thumbnail of the image
-transparent color make this color transparent within the image
-trim trim image edges
-type type image typeMiscellaneous Options:
-debug events display copious debugging information
-help print program options
-list type print a list of supported option arguments
-log format format of debugging information
-version print version informationBy default, 'file' is written in the MIFF image format. To
specify a particular image format, precede the filename with an image
format name and a colon (i.e. ps:image) or specify the image type as
the filename suffix (i.e. image.ps). Specify 'file' as '-' for
standard input or output.
import: delegate library support not built-in '' (X11) @ error/import.c/ImportImageCommand/1282.
: command not foundlocal/bin/obsidian_to_anki.py: line 13:
/Users/bryanjenks/.local/bin/obsidian_to_anki.py: line 14: syntax error near unexpected token(' 'Users/bryanjenks/.local/bin/obsidian_to_anki.py: line 14:
md_parser = markdown.Markdown(
Now when i run like
python ~/.local/bin/obsidian_to_anki.py -f c393.md
Traceback (most recent call last): File "/Users/bryanjenks/.local/bin/obsidian_to_anki.py", line 5, in import urllib.request ImportError: No module named request
but i have urllib installed, though i installed python 3.8 with brew the library is called urllib3
now when i change the script to import urllib3 that doesnt work either and it still doesn't find it. im honestly at a loss at the moment
MacOS Catalina latest version
zsh
latest verson of script
gooey installed
get this output:
2020-09-14 00:19:35.492 Python[96244:9342388] CoreText note: Client requested name ".SFNS-Regular", it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].
2020-09-14 00:19:35.492 Python[96244:9342388] CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug.
everything was set to defaults, script in in directory with 1 file, that one file has default syntax from repo readme:
TARGET DECK
Default
{Begin Note}
Basic
This is a test.
Back: Test successful!
{End Note}
{Begin Inline Note} [Basic] This is a test. Back: Test successful! {End Inline Note}
nothing was converted into Anki besides the deck if it didn't exist, but they always stay empty
This line should not be detected as a card, but it was detected as a cloze.
Similar things could happen to a list in markdown file like this one below:
thus i get a lot of empty card in my queue.
2.
This line is a cloze, but the "c1|" is not translated into "c1::" and the two dollar sign in between is not into "\(" or "\)".
Hi, I'm having trouble installing Goeey from my machine (Manjaro Linux, up to date). It seems that for Linux distributions it is harder install Gooey. It says to install for python2 but your script is for python3, which doesn't make any sense.
So, how to run just in command line like earlier versions?
Thanks
Edit: Because if I try to run give me "Gooey" is not installed:
> python3 obsidian_to_anki.py
Traceback (most recent call last):
File "obsidian_to_anki.py", line 12, in <module>
import gooey
ModuleNotFoundError: No module named 'gooey'
Error when running the script. The script doesn't add the cards to Anki.
Note that the image "Pasted image 2020201028224417.png" does exist.
Edit: if I delete the aforementioned image, the script continues to run until the next file containing an image, where it produces the same error.
On Windows 10 Pro 1903
Using Python 3.7.0, same with Python 3.8.5
Using the remnote syntax + custom syntax [3 colons = Basic (and reversed)].
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 881, in __init__
os.getcwd(), regex=args.regex
File ".\obsidian_to_anki.py", line 1441, in __init__
file.scan_file()
File ".\obsidian_to_anki.py", line 1311, in scan_file
self.search(note_type, regexp)
File ".\obsidian_to_anki.py", line 1373, in search
self.target_deck, url=self.url
File ".\obsidian_to_anki.py", line 625, in parse
template["fields"] = self.fields
File ".\obsidian_to_anki.py", line 617, in fields
for key, value in fields.items()
File ".\obsidian_to_anki.py", line 617, in <dictcomp>
for key, value in fields.items()
File ".\obsidian_to_anki.py", line 395, in format
FormatConverter.get_images(note_text)
File ".\obsidian_to_anki.py", line 328, in get_images
MEDIA[filename] = file_encode(path)
File ".\obsidian_to_anki.py", line 104, in file_encode
with open(filepath, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'attachments/Pasted%20image%2020201028224417.png' ```
The first field named doesn't have to be mentioned. Which I can see as an advantage when manually creating the markdown files but when generating markdown files using scripts it's a little harder. If optionally naming the first field is allowed then the fields and the values can be generated in any order and this in turn makes the scripting much easier.
Hi again, this is not an issue, but I don't know where to request a feature 🤷♂️
I would like to have a fixed field like that of FILE TAGS for all cards from .md file. One of the best plugins that I use on Anki is Frozen Fields, but how this can be done on Obsidian_to_Anki? It will make files more cleaner.
Example, if I have a custom card with 3 fields: Context (C:), Question (Q:), Answer (A:):
C: What is the country's capital?
Q: USA?
A: Washington, DC.
Q: Brazil?
A: Brasilia
Is it possible to repeat the same C: for every card?
Thanks
I've tried everything under the Sun to try to get card types working with markdown-header style of the Regex syntax, but I haven't been able to get to switch card type for the life of me. It's works completely fine with the default syntax. Could you please add examples on how to change card types with custom syntax too?
EDIT : So far I've only been using the default "Basic" card type, and love it thus far! But for anything non-basic I'm currently directly having to use Anki.
Hi, this is a feature request.
If you are familiar with glutanimate's addon, I think it would be really useful if the image occlusion tool could open and be used for images that you specify in the markdown file.
How I would imagine this happening:
I am not familiar with Anki's source code or Ankiconnect so am unsure how difficult this would be to implement.
I find that if the TARGET DECK line is placed at the end of the note, it is not omitted from the note in ANKI.
It shouldn't be so, right?
I found that the font size of the card made by obsidian_to_anki.py is too big. So, I made a comparison between anki-made cards and obsidian_to_anki.py made cards.
The follow picture is made by anki:
The follow picture is made by obsidian_to_anki.py:
The card made by obsidian_to_anki.py whose font size is too big, how can i change it?
Thank you very much!
Hello,
I am trying to import a markdown with a dozen cards. However, it doesn't recognize some of the last cards for some unknown reason. I am attaching the problematic file: Calculus.md.zip.
Also, as a potential feature request, do you think it could be possible to modify the regex so that the answers from a card can include blank lines? I tried a solution myself with the following regex but without success: ^## (.+)\n+((?:.|\n)+?END)
I have follow how-create-automated-task-using-task-scheduler-windows-10 and add the schedule like this:
C:\Users\Leon\OneDrive\_ApplicationData\ObsdianLibrary\.addon\obsidian_to_anki.py-d C:\Users\Leon\OneDrive\_ApplicationData\ObsdianLibrary -r -R
The window will appear and need click to finish the sync:
It works well , but if the script can run silently without any GUI/click it will be better.
Whenever I run the script in a directory, it changes the 'last modified' date even if the file hadn't any cards.
It's okay to modify the files with cards to add the scripts, but I don't think this should happen with the files without cards.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.