• # En python 3.7

    Posté par . En réponse au journal recherche-totoz en JavaScript. Évalué à 2. Dernière modification le 05 décembre 2018 à 00:09.

    En utilisant la lib trio

    import trio
    import untangle
    import fire
    import asks
    asks.init('trio')
    async def totoz(arg):
     r = await asks.get('https://totoz.eu/search.xml',
     params={'terms': arg})
     if r.status_code != 200:
     raise Exception(f'fail searchin {arg} ({r.status_code})')
     xml = untangle.parse(r.body.decode())
     for totoz in xml.totozes.totoz:
     print(totoz.name.cdata)
    async def asearch(*args):
     async with trio.open_nursery() as nurse:
     for arg in args:
     nurse.start_soon(totoz, arg)
    def search(*args):
     trio.run(asearch, *args)
    if __name__ == '__main__':
     fire.Fire(search)

    Pour plus d'intérêt ici, on peut passer plusieurs arguments à rechercher au script qui seront du coups exécutés parallèlement.

    Le module fire est pratique pour faire des programmes en cli.

    python totoz.py moule pas fraiche