Obsidian_to_Anki
Obsidian_to_Anki copied to clipboard
Save notes to the corresponding deck according to the folder structure
Just add an option inside the settings, and then based on that option, this code makes this change to realize this function.
So this annoyed me a lot... So I made a quick python script that will modify the data.json file within the plugin folder and copy the folder path to the folder deck. If you have anything there already it won't overrid it, just fill in the empty ones. It's pretty hacky though. I had to close obsidian after running it so the plugin loads the new data. And when I ran the anki extension after my changes it re-created part of my folder structure as decks. Even when there wasn't any cards to create in those folders/decks. So, anyway use this at your own risk, i bear no reposibility if you lose anything. And backup everything. Otherwise I'll keep using it myself until a solution comes up.
EDIT: fix minor code issue
import json
obsidian_to_anki_path = r"" # change this to the path to the 'obsidian_to_anki' extension folder
obsidian_to_anki_path = obsidian_to_anki_path + '\data.json'
max_deck_path_length = 6 # change this to determine how far in the folder path the deck replicates your paths.
with open(obsidian_to_anki_path, 'r') as f:
data = json.load(f)
folder_decks = data.get('settings').get('FOLDER_DECKS')
# replace the deck path with the folder it was found in
for k, v in folder_decks.items():
if not v:
v = k.replace('/', '::')
deck = v.split('::')[0:max_deck_path_length]
else:
deck = v.split('::')
deck = '::'.join(deck)
folder_decks[k] = deck
# replace the data in settings
data['settings']['FOLDER_DECKS'] = folder_decks
with open(obsidian_to_anki_path, 'w') as f:
json.dump(data, f)
So this annoyed me a lot... So I made a quick python script that will modify the data.json file within the plugin folder and copy the folder path to the folder deck. If you have anything there already it won't overrid it, just fill in the empty ones. It's pretty hacky though. I had to close obsidian after running it so the plugin loads the new data. And when I ran the anki extension after my changes it re-created part of my folder structure as decks. Even when there wasn't any cards to create in those folders/decks. So, anyway use this at your own risk, i bear no reposibility if you lose anything. And backup everything. Otherwise I'll keep using it myself until a solution comes up.
import json obsidian_to_anki_path = r"" # change this to the path to the 'obsidian_to_anki' extension folder obsidian_to_anki_path = obsidian_to_anki_path + '\data.json' max_deck_path_length = 6 # change this to determine how far in the folder path the deck replicates your paths. with open(obsidian_to_anki_path, 'r') as f: data = json.load(f) folder_decks = data.get('settings').get('FOLDER_DECKS') # replace the deck path with the folder it was found in for k, v in folder_decks.items(): if not v: v = k.replace('/', '::') deck = v.split('::') else: deck = v.split('::')[0:max_deck_path_length] deck = '::'.join(deck) folder_decks[k] = v # replace the data in settings data['settings']['FOLDER_DECKS'] = folder_decks with open(obsidian_to_anki_path, 'w') as f: json.dump(data, f)
You can use my modified version here I added this feature and added anki to obsidian links for the cards. I use it every day and haven't found any bugs so far