Created
January 27, 2018 14:58
-
-
Save hartym/ea4569efd220a2f103fad04e64daefcd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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