The Hypermodern Python Project

License

MIT License

Copyright (c) 2020 LuckyDams

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Reference

modern_python.console

Command-line interface.

modern_python.wikipedia

Client for the Wikipedia REST API, version 1.

class modern_python.wikipedia.Page(title, extract)

Page resource.

title

The title of the Wikipedia page.

extract

A plain text summary.

modern_python.wikipedia.random_page(language='en')

Return a random page.

Performs a GET request to the /page/random/summary endpoint.

Parameters

language (str) – The Wikipedia language edition. By default, the English Wikipedia is used (“en”).

Return type

Page

Returns

A page resource.

Raises

ClickException – The HTTP request failed or the HTTP response contained an invalid body.

Example

>>> from modern_python import wikipedia
>>> page = wikipedia.random_page(language="en")
>>> bool(page.title)
True

The example project for the Hypermodern Python article series. The command-line interface prints random facts to your console, using the Wikipedia API.

Installation

To install the Hypermodern Python project, run this command in your terminal:

$ pip install hypermodern-python

Usage

Hypermodern Python’s usage looks like:

$ hypermodern-python [OPTIONS]
-l <language>, --language <language>

The Wikipedia language edition, as identified by its subdomain on wikipedia.org. By default, the English Wikipedia is selected.

--version

Display the version and exit.

--help

Display a short usage message and exit.