The Hypermodern Python Console Project

License

MIT License

Copyright (c) [2022] [Kevin Bowen]

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

wiki_con.console

Command-line interface.

wiki_con.wikipedia

Client for the Wikipedia REST API, version 1.

class wiki_con.wikipedia.Page(title, extract)

Page resource.

title

The title of the Wikipedia page.

Type

str

extract

A plain text summary.

Type

str

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

Return a random page.

Perform 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 wiki_con import wikipedia
>>> page = wikipedia.random_page(language="en")
>>> bool(page.title)
True

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

Installation

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

$ pip install wiki-con

Usage

wiki_con’s usage looks like:

$ wiki_con [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.

Credits

The code for this project is originally from the Hypermodern Python article series.