Skip to content

Instantly share code, notes, and snippets.

@hartym
Created January 27, 2018 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hartym/ea4569efd220a2f103fad04e64daefcd to your computer and use it in GitHub Desktop.
Save hartym/ea4569efd220a2f103fad04e64daefcd to your computer and use it in GitHub Desktop.
import bonobo
from bonobo.config import ContextProcessor, use_context
from bonobo.constants import NOT_MODIFIED
def extract():
yield 'hello'
yield 'world'
@use_context
class MyXmlWriter(bonobo.FileWriter):
@ContextProcessor
def xml(self, context, file, *args, **kwargs):
file.write('<document>\n')
yield
file.write('</document>\n')
def __call__(self, file, context, line, *, fs):
file.write(' <line>'+line+'</line>\n')
return NOT_MODIFIED
def get_graph(**options):
graph = bonobo.Graph()
graph.add_chain(extract, MyXmlWriter('out.xml'))
return graph
if __name__ == '__main__':
parser = bonobo.get_argument_parser()
with bonobo.parse_args(parser) as options:
bonobo.run(
get_graph(**options),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment