Exemple #1
0
def main():
    words = ['贸易战', '世界杯'] * 50
    baidu_url = 'https://www.baidu.com/s?wd=%s'
    urls = [baidu_url % (word) for word in words]

    # make data flow net
    p1 = Pipe(
        urls,
        HttpLoader(),
        Branch(get_all_items, collect),
        Branch(get_all_page_url, HttpLoader(), get_all_items, collect),
    )
    Pipe(Timer(delay=delay), show_progress)
    BotFlow.run()
Exemple #2
0
def test_filter3():
    BotFlow.reset()
    Pipe([A(), B(), C()],
         Filter(filter_types=[A, B],
                filter_func=lambda r: isinstance(r, (A, C))), only_a)

    BotFlow.run()
Exemple #3
0
def main():

    Pipe(
        Timer(delay=1, max_time=10),
        Branch(very_slow),
        print,
    )

    BotFlow.run()
Exemple #4
0
def test_double_loop():
    BotFlow.reset()
    count = 0

    def sum(x):
        nonlocal count
        count += x

    p = Pipe(range(10), range(10), sum)

    BotFlow.run()
    assert count == 45 * 10
Exemple #5
0
def main():
    Pipe(
        range(10),
        Join(double, triple),
        plus_one,
        plus_one,
        Zip(n_stream=2),
        print_out,
    )

    BotFlow.render('ex_output/blockedjoin')
    BotFlow.run()
Exemple #6
0
def test_routetype_count():
    BotFlow.reset()
    b_counter = Counter()
    a_counter = Counter()
    Pipe([A(), B(), A()],
         Branch(only_a,
                a_counter,
                a_to_b,
                route_type=A,
                share=False,
                join=True), only_b, b_counter)
    BotFlow.run()
    assert (b_counter.count == 3)
    assert (a_counter.count == 2)
Exemple #7
0
def test_routetype_count3():
    BotFlow.reset()
    a_counter = Counter()
    b_counter = Counter()
    c_counter = Counter()

    p = Pipe(
        [A(), B(), A(), C(), C()],
        Branch(lambda i: isinstance(i, (A, C)), route_type=[A, C]),
        Branch(Branch(only_c, c_counter, route_type=C),
               share=False,
               route_type=[A, C]),
    )

    BotFlow.run()
    assert (c_counter.count == 2)
Exemple #8
0
def test_stop():
    def check_stop(i):
        if i > 10:
            BotFlow.stop()

        return i

    BotFlow.reset()
    Pipe(
        range(10000),
        Delay(),
        check_stop,
        print,
    )
    BotFlow.run()
    assert True
def main():

    hget = HttpLoader(timeout=2)

    Pipe(
        Timer(delay=3, max_time=5),
        Join(
            Return("https://api.kraken.com/0/public/Ticker?pair=XBTUSD", hget,
                   parse_kraken),
            Return(
                "https://bittrex.com/api/v1.1/public/getticker?market=USD-BTC",
                hget, parse_bittrex),
        ),
        print,
    )

    BotFlow.render('ex_output/bitcoin_arbitrage')
    BotFlow.run()
def main():
    words = ['贸易战', '世界杯']
    baidu_url = 'https://www.baidu.com/s?wd=%s'
    urls = [baidu_url % (word) for word in words]




    outputfile=AioFile('ex_output/baidu.txt')
    Pipe(
        urls,
        HttpLoader(),
       Branch(get_all_items,outputfile),
       Branch(get_all_page_url, HttpLoader(), get_all_items, outputfile),

    )
    #生成流程图
    BotFlow.debug_print()
    BotFlow.render('ex_output/baiduspider')
    BotFlow.run()
Exemple #11
0
def main():

    httpload = HttpLoader(timeout=2)
    Pipe(
        Timer(delay=2, max_time=5),
        Join(
            Return("https://api.kraken.com/0/public/Ticker?pair=XBTUSD",
                   httpload, parse_kraken),
            Return(
                "https://bittrex.com/api/v1.1/public/getticker?market=USD-BTC",
                httpload, parse_bittrex),
            Return("https://www.bitstamp.net/api/ticker/", httpload,
                   parse_bitstamp),
            Return("https://api.bitfinex.com/v1/ticker/btcusd", httpload,
                   parse_bitfinex),
            Return("https://bitpay.com/api/rates", httpload, parse_bitpay),
            Return("http://api.coindesk.com/v1/bpi/currentprice.json",
                   httpload, parse_coindesk),
        ), Zip(n_stream=6), print_list)

    BotFlow.render('ex_output/bitcoin_arbitrage')
    BotFlow.run()
Exemple #12
0
def test_routetype_count2():
    BotFlow.reset()
    b_counter = Counter()
    b1_counter = Counter()
    counter = Counter('count2')
    counter1 = Counter('count1')
    p = Pipe([A(), B(), A()],
             Branch(only_b, counter1, route_type=B, join=True, share=True),
             counter,
             Branch(only_a,
                    a_to_b,
                    only_b,
                    b1_counter,
                    route_type=A,
                    share=False,
                    join=True), only_b, b_counter)

    BotFlow.run()
    assert (counter1.count == 1)
    assert (counter.count == 4)

    assert (b1_counter.count == 2)
    assert (b_counter.count == 4)
Exemple #13
0
def main():
    Pipe(Loop(range(10)), double, triple, print)

    BotFrame.run()
Exemple #14
0
def test_routetype_no_shared():
    BotFlow.reset()
    Pipe([A(), B(), A()], Branch(only_a, route_type=A, share=False), only_b)
    BotFlow.run()
Exemple #15
0
def test_routetype():
    BotFlow.reset()
    Pipe([A(), B(), A()], Branch(only_a, route_type=A))
    BotFlow.run()
Exemple #16
0
#!/usr/bin/env python
from botflow import Bot, Pipe
from aiohttp import web

p = Pipe({"msg": "hello world!"}, {"error": "Botflow sucks!"},
         {"error": "Botflow sucks2!"})


def create_app():
    app = web.Application()

    app.add_routes([web.get('/', p.aiohttp_json_handle)])

    return app


if __name__ == '__main__':
    # BotFlow start web server http://0.0.0.0:8080
    app = create_app()
    Bot.run_app(app)
Exemple #17
0
def main():

    Pipe([A(), B(), A(), A(), B()], Branch(process_A,
                                           share=False,
                                           route_type=A), process_B)
    BotFlow.run()
Exemple #18
0
def test_filter():
    BotFlow.reset()
    Pipe([A(), B(), C()], Filter(filter_types=A), only_a)
    BotFlow.run()
Exemple #19
0
def test_filter2():

    BotFlow.reset()
    Pipe([A(), B(), C()], Filter(filter_func=lambda r: isinstance(r, A)),
         only_a)
    BotFlow.run()
Exemple #20
0
print('callable object')
s = typing.get_type_hints(func.__call__)
print(len(s))
print(s.values())

print(typing.get_type_hints(fun))

from botflow import Pipe, BotFlow


class A:
    pass


class B:
    pass


class C:
    pass


def only_a(data: A):

    assert isinstance(data, A)
    print("i got A")


Pipe([A(), B(), C()], only_a, print)

BotFlow.run()
Exemple #21
0
def main():
    Pipe(range(10), range(10), Branch(op_sum, print))

    BotFlow.run()
    print(op_sum)