Reference

hypermodern_python_tuto.__main__

Command-line interface.

hypermodern_python_tuto.ui

Utilities to show content to the user.

hypermodern_python_tuto.ui.print_wikipedia_article(wikipedia_article)

Show an article on the standard text output.

Prints in green the title, followed by the summary.

Parameters:

wikipedia_article (WikipediaArticle) – the article to print.

Return type:

None

Examples

>>> article = WikipediaArticle("a", "b")
>>> print_wikipedia_article(article)
a
b

hypermodern_python_tuto.wikipedia.article

WikipediaArticle class declaration.

class hypermodern_python_tuto.wikipedia.article.WikipediaArticle(title, summary)

Representation of the information needed about a Wikipedia article.

title

The title of the Wikipedia page.

summary

A plain text summary.

hypermodern_python_tuto.wikipedia.article_schema

WikipediaArticleSchema class declaration.

class hypermodern_python_tuto.wikipedia.article_schema.WikipediaArticleSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Validator for WikipediaArticle.

class Meta(name, bases, attrs)

Meta-information for marshmallow.

make_article(data, **_kwargs)

Create a WikipediaArticle after the validation.

Parameters:
  • data (dict[str, Any]) – Validated data.

  • **_kwargs (Any) – Unused args

Return type:

WikipediaArticle

Returns:

An instance of WikipediaArticle from the validated data.

hypermodern_python_tuto.wikipedia.language

Language enum declaration.

class hypermodern_python_tuto.wikipedia.language.Language(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Supported languages for the pages on the Wikipedia API (non-exhaustive).

classmethod from_preferences()

Search for the preferred language in the computer’s settings.

Since the computer settings vary a lot depending on the operating system, this function works on posix and Windows only.

Return type:

Language

Returns:

The preferred language.

Raises:

RuntimeError – If the os name is not posix or Windows.

Examples

>>> language = Language.from_preferences()
>>> isinstance(language, Language)
True
classmethod from_str(language)

Convert a language name to its equivalent Enum.

Parameters:

language (str) – The name of the language.

Return type:

Language

Returns:

The equivalent of the language in Enum.

Warning

Inaccurate because it works by looking for the beginning of the name, e.g. “fresh” will be detected as FRENCH.

Examples

>>> Language.from_str("french") is Language.FRENCH
True
>>> Language.from_str("en") is Language.ENGLISH
True
>>> Language.from_str("unrecognized") is Language.OTHER
True

hypermodern_python_tuto.wikipedia.requester

WikipediaRequester class declaration.

class hypermodern_python_tuto.wikipedia.requester.WikipediaRequester

Class to get information from Wikipedia.

get_random_article()

Query a random article from Wikipedia.

Return type:

WikipediaArticle

Returns:

A random article from Wikipedia (WikipediaArticle)

Example

>>> requester = WikipediaRequester()
>>> article = requester.get_random_article()
>>> bool(article)
True
set_language(language)

Specify the desired language of Wikipedia.

Parameters:

language (Language) – the desired language of Wikipedia. Default is English.

Return type:

None