Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
/ prop Public archive

Promises with opinions for asyncio and Python 3.6+

License

Notifications You must be signed in to change notification settings

HeavenVolkoff/prop

Repository files navigation

Prop (DEPRECATED)

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-2023 Vítor Vasconcellos. All rights reserved.

About

Promises with opinions for asyncio and Python 3.6+

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages