Esempio n. 1
0
    def test_filter3(self):

        Pipe([A(), B(), C()],
             Filter(route_type=[A, B],
                    route_func=lambda r: isinstance(r, (A, C))), self.only_a)

        BotFrame.run()
Esempio n. 2
0
def main():
    print('ex1----')
    Pipe(
        Loop(range(1)),
        Query('select * from mysql.user limit 10 ', **dbconf, map_class=User),
        Fork(print),
        Insert('insert into jk.new_table(user,host)values ("{user}","{host}")',
               **dbconf),
    )

    BotFrame.run()
Esempio n. 3
0
def main():

    Pipe(Loop([A(), B(), A(), A(), B()]),
         Branch(process_A, share=False, route_type=A), process_B)
    BotFrame.run()

    print('----ex2')

    Pipe(Loop([A(), B(), A(), A(), B()]),
         Fork(process_A, route_type=A, share=False), process_B, print)
    BotFrame.run()
Esempio n. 4
0
def main():
    Pipe(
        Timer(delay=2),  # send timer data to pipe every 2 sen
        "http://api.coindesk.com/v1/bpi/currentprice.json",  # send url to pipe when timer trigger
        HttpLoader(),  # read url and load http response
        lambda r: r.json['bpi']['USD'][
            'rate_float'],  # read http response and parese as json
        print,  # print out
    )

    BotFrame.render('simple_bitcoin_price')
    BotFrame.run()
Esempio n. 5
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(
        Loop(urls),
        HttpLoader(),
        Branch(get_all_items, collect),
        Branch(get_all_page_url, HttpLoader(), get_all_items, collect),
    )
    Pipe(Timer(delay=delay, until=p1.finished), show_progress)
    BotFrame.run()
Esempio n. 6
0
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),
    )
    #生成流程图
    BotFrame.render('ex_output/baiduspider')
    BotFrame.run()
Esempio n. 7
0
def main():

    hget = HttpLoader(timeout=2)

    Pipe(
        flow.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,
    )

    BotFrame.render('ex_output/bitcoin_arbitrage')
    BotFrame.run()
Esempio n. 8
0
def main():

    httpload=HttpLoader(timeout=2)
    Pipe(

        Timer(delay=10,max_time=5),
        BlockedJoin(
            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),
        ),
        print,
    )

    BotFrame.render('ex_output/bitcoin_arbitrage')
    BotFrame.run()
Esempio n. 9
0
def main():
    print('ex1----')
    Pipe(Loop(range(1)),
         Query('select * from mysql.user limit 10 ', **dbconf, map_class=User),
         print)

    BotFrame.run()

    print('ex2----param bind with inout')
    Pipe(Loop(range(10)), Query('select %s ', **dbconf), print)

    BotFrame.run()

    print('ex3----param bind with dict')
    u = User()
    u.user = '******'
    Pipe(
        Loop([{
            'user': '******'
        }, u.__dict__]),
        Query('select host,user from mysql.user where user="******" ',
              **dbconf), print)

    BotFrame.run()
Esempio n. 10
0
def main():

    Pipe(Timer(delay=0.5, max_time=10), FileSaver('a.txt'))

    BotFrame.run()
Esempio n. 11
0
    def test_filter(self):

        Pipe([A(), B(), C()], Filter(route_type=A), self.only_a)
        BotFrame.run()
Esempio n. 12
0
    def test_filter2(self):

        Pipe([A(), B(), C()], Filter(route_func=lambda r: isinstance(r, A)),
             self.only_a)
        BotFrame.run()
Esempio n. 13
0
def main():
    Pipe(Loop(range(1000000)), Fork(op_sum), print)

    BotFrame.run()
    print(op_sum)
Esempio n. 14
0
def main():
    Pipe(Loop(range(10)), double, triple, print)

    BotFrame.run()
Esempio n. 15
0
def main():
    Pipe(range(10), BlockedJoin(double, triple), print)

    BotFrame.render('ex_output/blockedjoin')
    BotFrame.run()
Esempio n. 16
0
 def run(cls):
     BotFrame.run()
Esempio n. 17
0
def main():
    Pipe(Loop(range(10)), Loop(range(10)), Branch(op_sum, print))

    BotFrame.run()
    print(op_sum)