Git Product home page Git Product logo

prop's Introduction

Prop

project_badge version_badge coverage_badge license_badge

Promises with opinions for asyncio and Python 3.6+

This is a revitalization of a promise submodule previously included in another project of mine: aRx. For older revisions of the code check there.

Summary

  • docs:

    Folder containing project's documentation

  • src:

    Folder containing project's source code

  • tests:

    Folder containing project's unit tests

  • tools:

    Folder containing tools for formatting and organizing the code

Examples

# pip install lxml asks prop
import asks
import lxml.html

from prop import Promise
from asyncio import get_event_loop

loop = get_event_loop()

p = (
    Promise(asks.get("https://en.wikipedia.org/wiki/Main_Page"), loop=loop)
    .then(
        lambda response: lxml.html.fromstring(response.text).xpath(
            '//*[contains(text(), "Did you know...")]/../following-sibling::*/ul//li'
        )
    )
    .catch(
        # In case the request fails or lxml can't parse the response, continues with empty list
        lambda _: []
    )
    .then(lambda lis: "\n".join(("Did you know:", *(li.text_content() for li in lis))))
    .then(print)
)

loop.run_until_complete(p)

Installation

$ pip install prop

License

All of the source code in this repository is available under the Mozilla Public License 2.0 (MPL). Those that require reproduction of the license text in the distribution are given here.

Copyright

Copyright (c) 2018 Vítor Augusto da Silva Vasconcellos. All rights reserved.

prop's People

Contributors

almeida-raphael avatar heavenvolkoff avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.