saucebrush/examples/test-splitter.py
James Turk 5421c12acd some cleanups discovered via test-splitter.py failure
* recipe is now a kwarg to Filter.__call__
* recipe.reject_record
* Splitter works with iterables
2010-02-20 11:14:23 -05:00

17 lines
644 B
Python

from saucebrush.filters import Splitter, PhoneNumberCleaner, FieldMerger, FieldAdder
from saucebrush.emitters import DebugEmitter
import operator
from itertools import count
import saucebrush
data = [{'person': {'firstname': 'James', 'lastname': 'Turk'},
'phones': [{'phone': '222-222-2222'}, {'phone': '(202) 333-3321'}]
}]
namemerger = FieldMerger({'name': ('firstname', 'lastname')}, lambda x,y: ' '.join((x,y)))
phonecleaner = PhoneNumberCleaner(('phone',))
splitter = Splitter({'person':[namemerger], 'phones':[phonecleaner]})
ider = FieldAdder('id', count())
saucebrush.run_recipe(data, ider, splitter, DebugEmitter())