taylormitchell / ankify_roam

A command-line tool which brings flashcards created in Roam to Anki.
MIT License
36 stars 6 forks source link

Problem with updating cards? #15

Open Etyre opened 3 years ago

Etyre commented 3 years ago

First of all, thanks for building this. Having a two-way interface between my roam database and anki makes both MUCH more useful. This has become one of the few systems that I use on a literally daily basis.

I'm currently running into a bug: for at least some cards, when I make changes to corresponding block in roam, that card is not updated when I run the script.

I double checked, and the uid field on the anki card matches the id of the roam block (and when I click on the asterisk, it does link me back to the block in my browser).

I'm still getting all the terminal messages that indicate success...

2021-03-19 19:46:10,070 - INFO - Setting up Ankifier 2021-03-19 19:46:10,241 - INFO - Loading Roam Graph 2021-03-19 19:47:02,041 - INFO - Fetching blocks to ankify 2021-03-19 19:47:02,188 - INFO - Ankifying 157 blocks 2021-03-19 19:47:10,116 - INFO - Added 0 new notes and updated 157 existing notes

...so I'm pretty confident that the script is working.

Is this a known bug?

taylormitchell commented 3 years ago

I'm glad you're finding the tool so useful! I get a ton of value out of it and/but it's great to hear that other's are as well.

This sounds like a bug I'd run into previously but it sounds like it's not fully fixed. If I remember correctly, there was a character encoding issue which was causing ankify_roam to fail to match up some blocks with the corresponding anki cards. I'm sure this is something we can get fixed, but I'm going to need some help from you to replicate the issue on my end.

I'll need the raw json of the blocks which are having the problem. Here's what I'll need you to do to create a json with the problematic blocks:

  1. Get the uids for a few of the blocks which aren't updating
  2. Follow the steps below to create a json of those blocks (I don't need or want your whole roam graph)
  3. Paste the contents of the json here, or send the json to: taylor.j.mitchell@gmail.com

Once I have the json and can replicate the issue, I should be able to turn around a fix pretty quickly.


Steps to create a json of select blocks

  1. Get the uids for a few of the blocks which aren't updating
  2. Export your roam graph as a json and unzip it
  3. Copy the python script below and paste it into a file called extract_buggy_blocks.py
  4. Place extract_buggy_blocks.py in the same folder as your roam graph (e.g. your Downloads folder)
  5. Run the extract_buggy_blocks.py script. The first parameter is the path to your roam graph export and the remaining parameters are the block uids. The script will load your roam graph, select the blocks with the uids you gave, and save those blocks as a separate json called buggy_blocks.json. Running it will look something like:
    cd ~/Downloads
    python extract_buggy_blocks.py my_roam_graph.json WAjKH-S05 4z-Ud6kRx
  6. You should now have a buggy_blocks.json file in the same folder where you ran the script from.

extract_buggy_blocks.py

import os
import json
import sys

def get_block(uid, blocks):
    for block in blocks:
        if block.get("uid") == uid:
            return block
        block = get_block(uid, block.get('children',[]))
        if block:
            return block
    return None

def main():
    # User inputs
    path = sys.argv[1]
    uids = sys.argv[2:]
    # Load roam graph
    with open(os.path.expanduser(path)) as f:
        rm = json.load(f)
    # Get blocks with given uids   
    select_blocks = []
    for uid in uids:
        for page in rm:
            block = get_block(uid, page.get('children',[]))
            if block:
                select_blocks.append(block)
    # Save blocks as json
    dir, _ = os.path.split(os.path.expanduser(path))
    with open(os.path.join(dir, "buggy_blocks.json"), "w") as f:
        json.dump(select_blocks, f)

if __name__=="__main__":
    main()
Etyre commented 3 years ago

Ok. I'll get to this sometime this weekend, and then let you know.

Etyre commented 3 years ago

Sent.

monk-blade commented 3 years ago

UTF 8 Same error.