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

@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.

@Pseudonium: yes it works now. Many thanks for a useful script.

1 piece of advice, if I may:
since Anki uses the Basic (and reversed card) term, I think you should use that terminology too, as you have done in the config.ini file.

Therefore, you should amend the “Config” section in your README.md file, because it will cause confusion, as it did with me when I followed your README file.

1 Like

@Klaas Wow, I didn’t catch that! Amended it now - I must’ve thought it was Basic (and reversed) as well.

1 Like

@Pseudonium: I have 1 more question.

On your Github page you state:

To update the config file with new note types from Anki, run obsidian_to_anki.py -u

When does one need to run that? Each time a card or a bunch of cards has been added?

@Klaas so you might run that when you add new note types to Anki, and want the script to be able to use them.

Ah, yes, new note types. So, as long as I continue with the note types defines in config.ini there is no need to run that script. Right?

Yep, you’ve got the right idea.

Small update - v1.1 now allows you to specify ‘global tags’ for a file, so you don’t need to repeat the same tags for a bunch of similar notes.

1 Like

How/where are those global tags specified?

It’s on a file-level basis. You format it as
GLOBAL TAGS
{Tag_list}

, and it will add all tags from {Tag_list} to all notes in the file.

I’ve updated README.md to reflect the new functionality.

@Pseudonium: I take it that by “file” you mean “folder”, i.e. the vault, and by “note” you mean an ".md file in there.

If that is correct, then what do you mean when you write in the README on your Github page:

To do this: Anywhere within the file, format the global tags as follows:
GLOBAL TAGS
{Tag_list}

“Anywhere within the file” as per my previous paragraph means “anywhere within the folder”, but how can one format global tags in a folder?

Does it mean I should create an .md file within the folder/vault with just

GLOBAL TAGS
{Tag_list}

I actually do mean file. You can specify global tags on a file-level, but not on a directory-level. So in the file you have notes in, you add the GLOBAL TAGS line.

@Pseudonium: OK. So I can add that to any 1 of those .md files and the tags will be added to every card I create from that vault? I only need to add it to just 1 .md file in the vault?

Not from the vault, no - just from that file.

I might be able to implement a specialised tag-file that does it for all in the vault, if you think that would be useful.

@Pseudonium: we’re still misaligned.

When you say:

So in the file you have notes in ……

What do you mean by “file”?
Or perhaps I should ask what do you mean by notes? To me notes means .md files, and those files/notes are sitting in a folder called the vault.

That is not what you means, so you have lost me, completely !

@Klaas Ah I can see how that would be confusing. So for me, notes =/=.md file - notes are the actual text/images inside a file.

By ‘file’, I mean actual .md file.

So, as an example:

GLOBAL TAGS
Literature Philosophy

START
Basic
This is a test
Back: Test successful!
Tags: Test
END

If you pasted that into a file, and saved it, and then ran the script over it, it would add a single ‘Basic’ note into Anki, with the tags “Literature”, “Philosophy” and “Test”, even though you only specified the “Test” tag inside the note itself.

Sorry, it’s probably extra confusing because Anki gives almost a third meaning to ‘note’, since cards are generated from notes!

So, to summarise:

  • For you, a ‘note’ is a .md file
  • For me, a ‘note’ is a piece of text inside a file about a topic (which might be formatted appropriately for Anki, or outside separately)
  • For Anki, a ‘note’ is something from which cards are generated, according to your template for that note type

@Pseudonium: OK it is clearer now. And to drive away the last doubt, taking your example above, once I have put

GLOBAL TAGS
Literature Philosophy

in any single .md file, each subsequent file that gets “Ankified” will get the tags “Literature” and “Philosophy” added.