Obsidian_to_Anki v3.4.0 - a feature-rich plugin that allows you to add notes from Obsidian to Anki

Thanks for building this so that I didn’t have to, hah!

I wonder if there’s a way to achieve some kind of syncing. E.g., if you update a note in Obsidian, is there a way to make sure the associated Anki card(s) get updated rather than creating new ones…? Hm.

So at the moment it works on a per-file basis. You’d have to go through the files individually.
I’ve set a flag to disallow duplicates (from AnkiConnect), but I haven’t tested it.

1 Like

So there is a part of the AnkiConnect API that allows you to update an existing note rather than create a new note. I haven’t looked into it that much though.

2 Likes

So I did some testing, and the current script will not add duplicates. If you run it a second time on the same file, nothing happens.

I’ve just released v0.2, which should allow you to do this!

3 Likes

@ryanjamurphy: there is also this.

1 Like

Great!! Hope you will integrate your script into OB after its api releases;)

1 Like

Yeah hopefully that won’t be too much of a hassle. As long as the API gives me access to the text of the file, I shouldn’t have to make too many modifications.

I’m adding support for markdown formatting in the next release (so you can use bold, italics etc). It might be possible to auto-embed images as well, though I haven’t started working on that.

1 Like

I did not get it to run. I posted the output from my terminal on your Github page.

v0.4 - Markdown formatting and Embedded Images Update is out! Let me know if there are any problems.

@Pseudonium: so if you have amended a card between the START and END, and you then run the script for a 2nd time on the file, it will not pick up those changes. Correct?

@Klaas For v0.2+ it does update automatically, this is only v0.1 behaviour

@Pseudonium: OK, clear. I plan to have a play tomorrow, and will give feedback.

Works great! Thanks!

Also if anyone can’t spare the 10 seconds to make it themself, I made an Alfred Workflow to make clozes as if in Anki:

Cloze-in-obsidian

1 Like

From your Github page:

To add appropriately-formatted notes from a file, run obsidian_to_anki -f {FILENAME}

Surely, just the filename is not enough, the script needs to know which Obs vault to look into. So, does {FILENAME} mean {path/to/vault/FILENAME}?

Yes, that is correct. I’ll amend the documentation to read ‘FILEPATH’ in v1.0

@Pseudonium: I ran this

Peters-MacBook-Air:Obsidian_to_Anki-master peter$ python3 obsidian_to_anki.py -f /Volumes/NO\ NAME/Test/Commercial\ art.md
Loading configuration file...
Loaded successfully!
Reading file /Volumes/NO NAME/Test/Commercial art.md into memory...
Traceback (most recent call last):
  File "obsidian_to_anki.py", line 576, in <module>
    App()
  File "obsidian_to_anki.py", line 394, in __init__
    self.target_deck = App.DECK_REGEXP.search(self.file).group(0)
AttributeError: 'NoneType' object has no attribute 'group'

Please note the .py needs to be included in the command - it is not in your instructions.

Now, after running the script I looked in Anki and did not find the new card.
Here is the full text of the Obsidian file:

---
Author: Hugh McLeod
Book: , p. 
Original number: n47
Site: [Brain Pickings](https://www.brainpickings.org/index.php/2012/02/27/purpose-work-love/)
Transcluded in: 
Note creation date: 2014-08-25
---
Tags: #creativity #wealth #commercialisation

---

> Art suffers the moment other people start paying for it.

*<!--PB:-->Lewis Hyde [[Creative labour|agrees]]*.
 
The reason is that when you start doing it to make money, you’re starting to kill yourself artistically. - [source](https://www.brainpickings.org/2014/05/13/pete-seeger-paul-zollo-songwriters-on-songwriting/)

<br>
<br>
<br>
<br>

START
Basic (and reversed)
Commercial art: when does it suffer?
Back: when people start paying for it
END


<br>

*Footnotes*
1 Like

v1.0 is now out! I’ll probably pause further development on the script for the time being - I feel like it has enough features to be useful.

@Klaas I realised that issue when running the v0.4 code myself actually! This should be fixed for v1.0

@Pseudonium: I still cannot get it to work. Below is the latest terminal output. Notice the key error in the last line.

Peters-MacBook-Air:Obsidian_to_Anki-master peter$ python3 obsidian_to_anki.py -f /Volumes/NO\ NAME/Test/Commercial\ art.md
Loading configuration file...
Loaded successfully!
Reading file /Volumes/NO NAME/Test/Commercial art.md into memory...
Traceback (most recent call last):
  File "obsidian_to_anki.py", line 576, in <module>
    App()
  File "obsidian_to_anki.py", line 394, in __init__
    self.target_deck = App.DECK_REGEXP.search(self.file).group(0)
AttributeError: 'NoneType' object has no attribute 'group'
Peters-MacBook-Air:Obsidian_to_Anki-master peter$ python3 obsidian_to_anki.py -u
Updating configuration file...
Config file exists, reading...
Configuration file updated!
Loading configuration file...
Loaded successfully!
Peters-MacBook-Air:Obsidian_to_Anki-master peter$ python3 obsidian_to_anki.py -f /Volumes/NO\ NAME/Test/Commercial\ art.md
Loading configuration file...
Loaded successfully!
Reading file /Volumes/NO NAME/Test/Commercial art.md into memory...
Identified target deck as Default
Scanning file for notes...
Traceback (most recent call last):
  File "obsidian_to_anki.py", line 576, in <module>
    App()
  File "obsidian_to_anki.py", line 398, in __init__
    self.scan_file()
  File "obsidian_to_anki.py", line 449, in scan_file
    parsed = Note(note).parse()
  File "obsidian_to_anki.py", line 218, in __init__
    self.note_type = Note.note_subs[self.lines[0]]
KeyError: 'Basic (and reversed)'

@Klaas I see the problem. You are describing the note type as ‘Basic (and reversed)’ - Anki actually stores it as ‘Basic (and reversed card)’.

If you’d like to refer to it as ‘Basic (and reversed)’, here’s what I suggest:

  1. Try running python3 obsidian_to_anki.py -c - this should open up the config file for editing. If that doesn’t work, you’ll have to navigate to the config file yourself.
  2. Once you’ve got the config file open, navigate to the section that says [‘Note Substitutions’]. It should be at the end of the file
  3. Then, change the line

Basic (and reversed card) = Basic (and reversed card)

To

Basic (and reversed card) = Basic (and reversed)

Save it, and then run the script again - it should work.