Big refactoring, way simpler management of transformations. Early branch for upcoming version 0.2.
This commit is contained in:
@ -3,8 +3,6 @@ from random import randint
|
||||
|
||||
from bonobo import Bag
|
||||
from bonobo.core.graphs import Graph
|
||||
from bonobo.core.strategies.executor import ThreadPoolExecutorStrategy
|
||||
from bonobo.ext.console import ConsoleOutputPlugin
|
||||
|
||||
|
||||
def extract():
|
||||
@ -23,11 +21,10 @@ def load(topic: str, title: str, wait: int):
|
||||
print('{} ({}) wait={}'.format(title, topic, wait))
|
||||
|
||||
|
||||
Strategy = ThreadPoolExecutorStrategy
|
||||
graph = Graph()
|
||||
graph.add_chain(extract, transform, load)
|
||||
|
||||
if __name__ == '__main__':
|
||||
etl = Graph()
|
||||
etl.add_chain(extract, transform, load)
|
||||
from bonobo.util.helpers import run
|
||||
|
||||
s = Strategy()
|
||||
s.execute(etl, plugins=[ConsoleOutputPlugin()])
|
||||
run(graph)
|
||||
@ -2,8 +2,6 @@ import time
|
||||
from random import randint
|
||||
|
||||
from bonobo.core.graphs import Graph
|
||||
from bonobo.core.strategies.executor import ThreadPoolExecutorStrategy
|
||||
from bonobo.ext.console import ConsoleOutputPlugin
|
||||
|
||||
|
||||
def extract():
|
||||
@ -25,11 +23,10 @@ def load(s):
|
||||
print(s)
|
||||
|
||||
|
||||
Strategy = ThreadPoolExecutorStrategy
|
||||
graph = Graph()
|
||||
graph.add_chain(extract, transform, load)
|
||||
|
||||
if __name__ == '__main__':
|
||||
etl = Graph()
|
||||
etl.add_chain(extract, transform, load)
|
||||
from bonobo import run
|
||||
|
||||
s = Strategy()
|
||||
s.execute(etl, plugins=[ConsoleOutputPlugin()])
|
||||
run(graph)
|
||||
20
examples/basics_file.py
Normal file
20
examples/basics_file.py
Normal file
@ -0,0 +1,20 @@
|
||||
from bonobo import FileReader, Graph
|
||||
|
||||
|
||||
def skip_comments(line):
|
||||
if not line.startswith('#'):
|
||||
yield line
|
||||
|
||||
|
||||
graph = Graph(
|
||||
FileReader(path='/etc/passwd'),
|
||||
skip_comments,
|
||||
lambda s: s.split(':'),
|
||||
lambda l: l[0],
|
||||
print,
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import bonobo
|
||||
|
||||
bonobo.run(graph)
|
||||
21
examples/basics_file_csv.py
Normal file
21
examples/basics_file_csv.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
from bonobo import CsvReader, Graph
|
||||
|
||||
__path__ = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def skip_comments(line):
|
||||
if not line.startswith('#'):
|
||||
yield line
|
||||
|
||||
|
||||
graph = Graph(
|
||||
CsvReader(path=os.path.join(__path__, 'datasets/coffeeshops.txt')),
|
||||
print,
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import bonobo
|
||||
|
||||
bonobo.run(graph)
|
||||
@ -2,8 +2,6 @@ import time
|
||||
from random import randint
|
||||
|
||||
from bonobo.core.graphs import Graph
|
||||
from bonobo.core.strategies.executor import ThreadPoolExecutorStrategy
|
||||
from bonobo.ext.console import ConsoleOutputPlugin
|
||||
|
||||
|
||||
def extract():
|
||||
@ -22,11 +20,10 @@ def load(s):
|
||||
print(s)
|
||||
|
||||
|
||||
Strategy = ThreadPoolExecutorStrategy
|
||||
graph = Graph()
|
||||
graph.add_chain(extract, transform, load)
|
||||
|
||||
if __name__ == '__main__':
|
||||
etl = Graph()
|
||||
etl.add_chain(extract, transform, load)
|
||||
from bonobo import run
|
||||
|
||||
s = Strategy()
|
||||
s.execute(etl, plugins=[ConsoleOutputPlugin()])
|
||||
run(graph)
|
||||
@ -1,8 +1,9 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from blessings import Terminal
|
||||
|
||||
from bonobo import console_run, tee, JsonWriter, Graph
|
||||
from bonobo import tee, JsonWriter, Graph
|
||||
from bonobo.ext.opendatasoft import from_opendatasoft_api
|
||||
|
||||
try:
|
||||
@ -15,6 +16,7 @@ API_NETLOC = 'datanova.laposte.fr'
|
||||
ROWS = 100
|
||||
|
||||
t = Terminal()
|
||||
__path__ = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def _getlink(x):
|
||||
@ -57,13 +59,17 @@ def display(row):
|
||||
|
||||
graph = Graph(
|
||||
from_opendatasoft_api(
|
||||
API_DATASET, netloc=API_NETLOC, timezone='Europe/Paris'
|
||||
API_DATASET,
|
||||
netloc=API_NETLOC,
|
||||
timezone='Europe/Paris'
|
||||
),
|
||||
normalize,
|
||||
filter_france,
|
||||
tee(display),
|
||||
JsonWriter('fablabs.json'),
|
||||
JsonWriter(path=os.path.join(__path__, 'datasets/coffeeshops.txt')),
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
console_run(graph, output=True)
|
||||
import bonobo
|
||||
|
||||
bonobo.run(graph)
|
||||
|
||||
Reference in New Issue
Block a user