Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save notes to the corresponding deck according to the folder structure #569

Open
norcx opened this issue Apr 13, 2024 · 2 comments
Open

Comments

@norcx
Copy link

norcx commented Apr 13, 2024

图片
Just add an option inside the settings, and then based on that option, this code makes this change to realize this function.

@Anthonyae
Copy link

Anthonyae commented Apr 26, 2024

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)

@norcx
Copy link
Author

norcx commented Apr 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants