taylormitchell / ankify_roam

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

KeyError: 'edit-time' when parsing json #1

Closed jacrify closed 4 years ago

jacrify commented 4 years ago

Some of my exported json nodes don't have edit-times or emails 🤷‍♂️.

Adding default values into the containers.py file (line 113) makes it run cleanly.

return cls(page['title'], child_block_objects, page.get('edit-time',''), page.get('edit-email',''))

Not submitting as a patch as I have a feeling you might be using edit-time somewhere, so you might want to set it high or low depending on it's use.

For reference, here's the original error:

2020-07-05 11:53:03,426 - INFO - Loading Roam Graph
Traceback (most recent call last):
  File "/Users/john/Library/Python/3.7/bin/ankify_roam", line 10, in <module>
    sys.exit(main())
  File "/Users/john/Library/Python/3.7/lib/python/site-packages/ankify_roam/cli.py", line 77, in main
    func(**args)
  File "/Users/john/Library/Python/3.7/lib/python/site-packages/ankify_roam/cli.py", line 17, in add
    roam_graph = RoamGraph.from_path(path)
  File "/Users/john/Library/Python/3.7/lib/python/site-packages/ankify_roam/roam/containers.py", line 23, in from_path
    return cls.from_json(path)
  File "/Users/john/Library/Python/3.7/lib/python/site-packages/ankify_roam/roam/containers.py", line 31, in from_json
    return cls(roam_pages)
  File "/Users/john/Library/Python/3.7/lib/python/site-packages/ankify_roam/roam/containers.py", line 12, in __init__
    self.pages = [Page.from_dict(p, self) for p in pages]
  File "/Users/john/Library/Python/3.7/lib/python/site-packages/ankify_roam/roam/containers.py", line 12, in <listcomp>
    self.pages = [Page.from_dict(p, self) for p in pages]
  File "/Users/john/Library/Python/3.7/lib/python/site-packages/ankify_roam/roam/containers.py", line 113, in from_dict
    return cls(page['title'], child_block_objects, page['edit-time'], page['edit-email'])
KeyError: 'edit-time'
taylormitchell commented 4 years ago

Weird that those attributes aren't always there. Thanks for pointing this out and for the solution!