Go to file
Andy Drop 5ab318f57f Added several writing methods 2021-12-15 17:05:13 +01:00
.ci Updates from upstream, and full fork 2021-11-16 17:15:21 +01:00
.github/workflows Updates from upstream, and full fork 2021-11-16 17:15:21 +01:00
doc Updates from upstream, and full fork 2021-11-16 17:15:21 +01:00
orgmodify Added several writing methods 2021-12-15 17:05:13 +01:00
.gitignore update CI scripts, add mypy checks 2020-11-01 17:04:43 +01:00
LICENSE cloned and renamed the orgparse project 2021-10-26 00:20:31 +02:00
Makefile Updates from upstream, and full fork 2021-11-16 17:15:21 +01:00
README.rst Correct heading in README.rst 2021-12-03 10:01:26 +01:00
mypy.ini update CI scripts, add mypy checks 2020-11-01 17:04:43 +01:00
pytest.ini Updates from upstream, and full fork 2021-11-16 17:15:21 +01:00
setup.py Converted the tags from a set to a unique list 2021-12-07 23:04:01 +01:00
tox.ini Re-established compatibility wit orgparse regarding dates 2021-12-13 03:12:20 +01:00

README.rst

orgmodify - Python module for modifying Emacs org-mode files

Install

pip install orgmodify

Usage

There are pretty extensive doctests if you're interested in some specific method. Otherwise here are some example snippets:

Load org node

from orgmodify import load, loads

load('PATH/TO/FILE.org')
load(file_like_object)

loads('''
* This is org-mode contents
  You can load org object from string.
** Second header
''')

Traverse org tree

>>> root = loads('''
... * Heading 1
... ** Heading 2
... *** Heading 3
... ''')
>>> for node in root[1:]:  # [1:] for skipping root itself
...     print(node)
* Heading 1
** Heading 2
*** Heading 3
>>> h1 = root.children[0]
>>> h2 = h1.children[0]
>>> h3 = h2.children[0]
>>> print(h1)
* Heading 1
>>> print(h2)
** Heading 2
>>> print(h3)
*** Heading 3
>>> print(h2.get_parent())
* Heading 1
>>> print(h3.get_parent(max_level=1))
* Heading 1

Accessing node attributes

>>> root = loads('''
... * DONE Heading          :TAG:
...   CLOSED: [2012-02-26 Sun 21:15] SCHEDULED: <2012-02-26 Sun>
...   CLOCK: [2012-02-26 Sun 21:10]--[2012-02-26 Sun 21:15] =>  0:05
...   :PROPERTIES:
...   :Effort:   1:00
...   :OtherProperty:   some text
...   :END:
...   Body texts...
... ''')
>>> node = root.children[0]
>>> node.heading
'Heading'
>>> node.scheduled
OrgDateScheduled((2012, 2, 26))
>>> node.closed
OrgDateClosed((2012, 2, 26, 21, 15, 0))
>>> node.clock
[OrgDateClock((2012, 2, 26, 21, 10, 0), (2012, 2, 26, 21, 15, 0))]
>>> bool(node.deadline)   # it is not specified
False
>>> node.tags == set(['TAG'])
True
>>> node.get_property('Effort')
60
>>> node.get_property('UndefinedProperty')  # returns None
>>> node.get_property('OtherProperty')
'some text'
>>> node.body
'  Body texts...'