Beispiel #1
0
def get_graph(graph=None, *, _limit=(), _print=()):
    """
    Extracts a list of cafes with on euro in Paris, renames the name, address and zipcode fields,
    reorders the fields and formats to json and csv files.

    """
    graph = graph or bonobo.Graph()

    producer = (
        graph.get_cursor() >> ODSReader(dataset="liste-des-cafes-a-un-euro",
                                        netloc="opendata.paris.fr") >>
        PartialGraph(*_limit) >> bonobo.UnpackItems(0) >> bonobo.Rename(
            name="nom_du_cafe", address="adresse", zipcode="arrondissement") >>
        bonobo.Format(city="Paris", country="France") >> bonobo.OrderFields([
            "name", "address", "zipcode", "city", "country", "geometry",
            "geoloc"
        ]) >> PartialGraph(*_print))

    # Comma separated values.
    graph.get_cursor(producer.output) >> bonobo.CsvWriter(
        "coffeeshops.csv",
        fields=["name", "address", "zipcode", "city"],
        delimiter=",")

    # Standard JSON
    graph.get_cursor(
        producer.output) >> bonobo.JsonWriter(path="coffeeshops.json")

    # Line-delimited JSON
    graph.get_cursor(
        producer.output) >> bonobo.LdjsonWriter(path="coffeeshops.ldjson")

    return graph
Beispiel #2
0
def get_graph(graph=None, *, _limit=(), _print=()):
    """
    Extracts a list of cafes with on euro in Paris, renames the name, address and zipcode fields,
    reorders the fields and formats to json and csv files.

    """
    graph = graph or bonobo.Graph()

    producer = graph.add_chain(
        ODSReader(dataset='liste-des-cafes-a-un-euro',
                  netloc='opendata.paris.fr'),
        *_limit,
        bonobo.UnpackItems(0),
        bonobo.Rename(name='nom_du_cafe',
                      address='adresse',
                      zipcode='arrondissement'),
        bonobo.Format(city='Paris', country='France'),
        bonobo.OrderFields([
            'name', 'address', 'zipcode', 'city', 'country', 'geometry',
            'geoloc'
        ]),
        *_print,
    )

    # Comma separated values.
    graph.add_chain(
        bonobo.CsvWriter('coffeeshops.csv',
                         fields=['name', 'address', 'zipcode', 'city'],
                         delimiter=','),
        _input=producer.output,
    )

    # Standard JSON
    graph.add_chain(
        bonobo.JsonWriter(path='coffeeshops.json'),
        _input=producer.output,
    )

    # Line-delimited JSON
    graph.add_chain(
        bonobo.LdjsonWriter(path='coffeeshops.ldjson'),
        _input=producer.output,
    )

    return graph
Beispiel #3
0
def get_graph(**options):
    """
    This function builds the graph that needs to be executed.

    :return: bonobo.Graph

    """
    graph = bonobo.Graph()

    split = bonobo.noop

    graph.add_chain(
        bonobo.CsvWriter('DeckedBuilder.csv'),
        # bonobo.Limit(10),
        metadata,
        # bonobo.UnpackItems(0),
        split,
        _input=None,
        _name='main',
    )

    graph.add_chain(
        bonobo.CsvReader('main-en.csv'),
        bonobo.Format(Language='English'),
        _output='main',
    )

    graph.add_chain(
        bonobo.CsvReader('main-de.csv'),
        bonobo.Format(Language='German'),
        _output='main',
    )

    graph.add_chain(
        bonobo.CsvReader('main-ru.csv'),
        bonobo.Format(Language='Russian'),
        _output='main',
    )

    graph.add_chain(
        bonobo.CsvReader('main-it.csv'),
        bonobo.Format(Language='Italian'),
        _output='main',
    )

    graph.add_chain(
        bonobo.CsvReader('main-jp.csv'),
        bonobo.Format(Language='Japanese'),
        _output='main',
    )

    graph.add_chain(
        bonobo.CsvReader('main-fr.csv'),
        bonobo.Format(Language='French'),
        _output='main',
    )

    graph.add_chain(
        bonobo.CsvReader('main-kr.csv'),
        bonobo.Format(Language='Korean'),
        _output='main',
    )

    graph.add_chain(
        bonobo.CsvReader('main-cs.csv'),
        bonobo.Format(Language='Chinese'),
        _output='main',
    )

    graph.add_chain(
        bonobo.CsvReader('Deckbox-extras.csv'),
        bonobo.Format(Language='English'),
        _output='main',
    )

    if ECHO_MTG:
        # Reg Qty,Foil Qty,Name,Set,Acquired,Language
        echomtg = {'Acquired For': '0.004', 'Language': 'en'}
        graph.add_chain(
            # echomtg specific fiddling
            remove_metadata,
            bonobo.UnpackItems(0),
            # bonobo.PrettyPrinter(),
            bonobo.Rename(Name='Card'),
            bonobo.Format(**echomtg),
            bonobo.CsvWriter('EchoMTG.csv'),
            _input=split,
        )

    # MTG Studio

    if MTG_STUDIO:
        graph.add_chain(
            mtg_studio,
            remove_metadata,
            bonobo.UnpackItems(0),
            # bonobo.Format(Edition='{Set}'),
            bonobo.Rename(Edition='Set'),
            # bonobo.Rename(Name='Card'),
            # bonobo.Rename(Qty='Reg Qty'),
            # bonobo.Rename(Foil='Foil Qty'),
            # bonobo.PrettyPrinter(),
            bonobo.CsvWriter('MTG-Studio.csv'),
            _input=split,
        )

    #    graph.add_chain(
    #        tradeable,
    #        bonobo.UnpackItems(0),
    #        #bonobo.PrettyPrinter(),
    #        #bonobo.Limit(3000),
    #        bonobo.CsvWriter("DeckedBuilder-tradelist.csv"),
    #        bonobo.OrderFields([
    #            'Card',
    #            'Set',
    #            'Foil',
    #            'Quantity',
    #        ]),
    #        bonobo.CsvWriter("CardKingdom-buylist.csv"),
    #        bonobo.OrderFields([
    #            'Quantity',
    #            'Card',
    #            'Set',
    #        ]),
    #        bonobo.CsvWriter(
    #            "mtgprice-buylist.csv",
    #            delimiter="\t",
    #        ),
    #        _input=split,
    #    )
    #
    if DECKBOX:
        csv_out = bonobo.CsvWriter('Deckbox-inventory.csv')

        graph.add_chain(
            #       # metadata,
            #        #bonobo.UnpackItems(0),
            deckbox,
            bonobo.UnpackItems(0),
            csv_out,
            _input=split,
        )

        graph.add_chain(bonobo.CsvReader('Deckbox-specials.csv'),
                        _output=csv_out)
    return graph