nnako / freeplane-python-io

a Python library to directly access Freeplane mindmap files
GNU General Public License v3.0
12 stars 5 forks source link

AttributeError: 'Node' object has no attribute 'set' #5

Closed Ekran closed 10 months ago

Ekran commented 10 months ago

I want to modify CREATED and MODIFIED. But I get the error AttributeError: 'Node' object has no attribute 'set' (Line 2623). And yes, the class node seems to have no method def set():.

The method set_attribute() adds something other: <node ID="ID_1234567890" CREATED="1705008101414" MODIFIED="1705008101414" TEXT="Test neu Root"><attribute NAME="ical_uid" VALUE="ID_1234567890"/>

To get the error insert in def test() the lines:

    # add node to root
    mm_parent_node = mm.rootnode
    new_node = mm_parent_node.add_child("new node")
    new_node2 = new_node.add_child("new child node")

    # change CREATE attribute
    _current_time = datetime.datetime.now()
    _current_timestamp = str(int(_current_time.timestamp() * 1000))
    # update_date_attribute_in_node(new_node2, date=_current_timestamp, key="MODIFIED") # fails
nnako commented 10 months ago

Hi @Ekran,

Thanks for your interest and question.

I'm afraid, you are trying to use the helper function update_date_attribute_in_node() directly on a freeplane node object. This will fail as a freeplane node object does not provide a set function internally. You would have to directly use the underlying XML object of that freeplane node object, which you get by the internal _node member of any freeplane node object. So, please try

update_date_attribute_in_node(new_node2._node, date=_current_timestamp, key="MODIFIED")

instead of the line you commented out in your example. And, please note the new_node2._node as the necessary change. At least in my understanding, the "normal" user is not supposed to touch the modification or creation dates manually (as this would also be difficult do do using the Freeplane editor). This is done automatically when creating or changing a node. But, yes, you can.

Does this work for you?

Regards. Nnako

Ekran commented 10 months ago

Thank you! Yes this works! I appreciate your effort in creating this library!

I like to work with mindmaps for tasks but have to use a caldav calendar with tasks. Some time ago I made a ics2mm.py and a mm2ics.py. But now I work on a synctool between caldav online calendar and mindmap file. So it is necessary to sync also created and last modifies time stamps.

(I found in my fist post, there was a line not shown because of a xml syntax, I edit this line.)