wikiquote


Namewikiquote JSON
Version 0.1.17 PyPI version JSON
download
home_pagehttps://github.com/federicotdn/wikiquote
SummaryRetrieve quotes from any Wikiquote article.
upload_time2023-08-20 12:50:49
maintainer
docs_urlNone
authorFederico Tedin
requires_python>=3.8, <4
licenseMIT
keywords quotes wikiquote python api qotd quote day
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # wikiquote
[![CI Status](https://github.com/federicotdn/wikiquote/workflows/CI/badge.svg)](https://github.com/federicotdn/wikiquote/actions)
![License](https://img.shields.io/pypi/l/wikiquote.svg?style=flat)
![](https://img.shields.io/badge/python-3-blue.svg)
[![Version](https://img.shields.io/pypi/v/wikiquote.svg?style=flat)](https://pypi.python.org/pypi/wikiquote)
![Black](https://img.shields.io/badge/code%20style-black-000000.svg)

The `wikiquote` package for Python (>=3.8) allows you to search and retrieve quotes from any [Wikiquote](https://www.wikiquote.org/) article, as well as retrieve the quote of the day.

## Installation
You can install the `wikiquote` package using `pip`:
```bash
$ pip install --upgrade wikiquote
```

## Usage
```python
>>> import wikiquote

>>> wikiquote.search('The Matrix')
# ['The Matrix (film)', 'The Matrix Revolutions', 'The Matrix Reloaded', 'The Animatrix']

>>> wikiquote.quotes('The Matrix (film)', max_quotes=2) # max_quotes defaults to 20
# ['Don't think you are, know you are.', 'Fate, it seems, is not without a sense of irony.']

>>> wikiquote.quote_of_the_day() # returns a (quote, author) tuple
# 'Always forgive your enemies; nothing annoys them so much.', 'Oscar Wilde'

>>> wikiquote.qotd() # same as quote_of_the_day()

>>> wikiquote.random_titles(max_titles=3) # max_titles defaults to 20
# ['The Lion King', 'Johannes Kepler', 'Rosa Parks']

>>> wikiquote.supported_languages()
# ['de', 'en', 'es', 'eu', 'fr', 'he', 'it', 'pl', 'pt']

```

Some article titles will lead to a Disambiguation page (like `Matrix`), which will raise a `DisambiguationPageException` exception. Usually this happens because there are many articles matching the search term. When this happens, try using `search()` first, and then use one of the specific article titles found.

If the article searched for does not exist, and no similar results exist, `NoSuchPageException` will be raised instead.

When requesting the quote of the day, a `MissingQOTDException` exception will be raised if the quote of the day could not be extracted from Wikiquote's main page. This usually happens because the page's layout has been changed.

## Languages
The `wikiquote` module currently supports the following languages:

| Language   | ISO 639-1 Code |
|------------|----------------|
| Basque     | `eu`           |
| English    | `en`           |
| French     | `fr`           |
| German     | `de`           |
| Hebrew     | `he`           |
| Italian    | `it`           |
| Polish     | `pl`           |
| Portuguese | `pt`           |
| Spanish    | `es`           |

Use the `lang` parameter to specify the language (defaults to `en`):
```python
>>> import wikiquote

>>> wikiquote.quotes('Dune', lang='en')[0]
# 'Parting with friends is a sadness. A place is only a place.'

>>> wikiquote.quotes('Victor Hugo', lang='fr')[0]
# 'Le plus lourd fardeau, c'est d'exister sans vivre.'

>>> wikiquote.quotes('Nueve reinas', lang='es')[0]
# 'Más ofendido estás... menos sospechoso parecés.'

>>> wikiquote.quote_of_the_day(lang='es')
# 'He sospechado alguna vez que la única cosa sin misterio es la felicidad, porque se justifica por sí sola.', 'Jorge Luis Borges'

>>> wikiquote.quotes('Hermann Hesse', lang='de')[0]
# 'Nun, aller höhere Humor fängt damit an, daß man die eigene Person nicht mehr ernst nimmt.'

>>> wikiquote.quote_of_the_day(lang='it')
# "Siamo angeli con un'ala sola. Possiamo volare solo restando abbracciati.", 'Luciano De Crescenzo'

>>> wikiquote.quote_of_the_day(lang='pl')
# 'Boże pomóż mi być takim człowiekiem, za jakiego uważa mnie mój pies.', 'Janusz Leon Wiśniewski'

>>> wikiquote.quotes('José Saramago', lang='pt')[0]
# 'Nem a juventude sabe o que pode, nem a velhice pode o que sabe.'
```

Specifying an invalid language will result in an `UnsupportedLanguageException` exception.

## Tips
Use `random.choice()` to select a random quote from an article:
```python
>>> import wikiquote, random

>>> random.choice(wikiquote.quotes('Linus Torvalds'))
# 'WE DO NOT BREAK USERSPACE!'
```

## Caveats
In some cases, `wikiquote` may fail to retrieve quotes from some articles, or the quote of the day (QOTD). This is due to Wikiquote.org's varying internal article layouts: some quotes may be contained in `div` elements, others in `li`, etc. depending on the article and the language.

## Developing
First, make sure you have installed all necessary dependencies, including development dependencies:
```bash
$ pip install -r requirements-dev.txt -r requirements.txt
```

Then, check that all files are correctly formatted, and that the type hints are also correct:
```bash
$ make lint
$ make types
```

After that, check that all tests pass:
```bash
$ make test
```
Some tests may be skipped in the QOTD is not available for some languages.

Finally, create a pull request stating your changes.

## Changelog
See the [CHANGELOG.md](CHANGELOG.md) file.

## License
The `wikiquote` package is licensed under the MIT License.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/federicotdn/wikiquote",
    "name": "wikiquote",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8, <4",
    "maintainer_email": "",
    "keywords": "quotes,wikiquote,python,api,qotd,quote,day",
    "author": "Federico Tedin",
    "author_email": "federicotedin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/36/db/403ca7d79e0719bfedb67e5a3f4b5de2d8b59bc9b9a7ce7a21eb47779d74/wikiquote-0.1.17.tar.gz",
    "platform": null,
    "description": "# wikiquote\n[![CI Status](https://github.com/federicotdn/wikiquote/workflows/CI/badge.svg)](https://github.com/federicotdn/wikiquote/actions)\n![License](https://img.shields.io/pypi/l/wikiquote.svg?style=flat)\n![](https://img.shields.io/badge/python-3-blue.svg)\n[![Version](https://img.shields.io/pypi/v/wikiquote.svg?style=flat)](https://pypi.python.org/pypi/wikiquote)\n![Black](https://img.shields.io/badge/code%20style-black-000000.svg)\n\nThe `wikiquote` package for Python (>=3.8) allows you to search and retrieve quotes from any [Wikiquote](https://www.wikiquote.org/) article, as well as retrieve the quote of the day.\n\n## Installation\nYou can install the `wikiquote` package using `pip`:\n```bash\n$ pip install --upgrade wikiquote\n```\n\n## Usage\n```python\n>>> import wikiquote\n\n>>> wikiquote.search('The Matrix')\n# ['The Matrix (film)', 'The Matrix Revolutions', 'The Matrix Reloaded', 'The Animatrix']\n\n>>> wikiquote.quotes('The Matrix (film)', max_quotes=2) # max_quotes defaults to 20\n# ['Don't think you are, know you are.', 'Fate, it seems, is not without a sense of irony.']\n\n>>> wikiquote.quote_of_the_day() # returns a (quote, author) tuple\n# 'Always forgive your enemies; nothing annoys them so much.', 'Oscar Wilde'\n\n>>> wikiquote.qotd() # same as quote_of_the_day()\n\n>>> wikiquote.random_titles(max_titles=3) # max_titles defaults to 20\n# ['The Lion King', 'Johannes Kepler', 'Rosa Parks']\n\n>>> wikiquote.supported_languages()\n# ['de', 'en', 'es', 'eu', 'fr', 'he', 'it', 'pl', 'pt']\n\n```\n\nSome article titles will lead to a Disambiguation page (like `Matrix`), which will raise a `DisambiguationPageException` exception. Usually this happens because there are many articles matching the search term. When this happens, try using `search()` first, and then use one of the specific article titles found.\n\nIf the article searched for does not exist, and no similar results exist, `NoSuchPageException` will be raised instead.\n\nWhen requesting the quote of the day, a `MissingQOTDException` exception will be raised if the quote of the day could not be extracted from Wikiquote's main page. This usually happens because the page's layout has been changed.\n\n## Languages\nThe `wikiquote` module currently supports the following languages:\n\n| Language   | ISO 639-1 Code |\n|------------|----------------|\n| Basque     | `eu`           |\n| English    | `en`           |\n| French     | `fr`           |\n| German     | `de`           |\n| Hebrew     | `he`           |\n| Italian    | `it`           |\n| Polish     | `pl`           |\n| Portuguese | `pt`           |\n| Spanish    | `es`           |\n\nUse the `lang` parameter to specify the language (defaults to `en`):\n```python\n>>> import wikiquote\n\n>>> wikiquote.quotes('Dune', lang='en')[0]\n# 'Parting with friends is a sadness. A place is only a place.'\n\n>>> wikiquote.quotes('Victor Hugo', lang='fr')[0]\n# 'Le plus lourd fardeau, c'est d'exister sans vivre.'\n\n>>> wikiquote.quotes('Nueve reinas', lang='es')[0]\n# 'M\u00e1s ofendido est\u00e1s... menos sospechoso parec\u00e9s.'\n\n>>> wikiquote.quote_of_the_day(lang='es')\n# 'He sospechado alguna vez que la \u00fanica cosa sin misterio es la felicidad, porque se justifica por s\u00ed sola.', 'Jorge Luis Borges'\n\n>>> wikiquote.quotes('Hermann Hesse', lang='de')[0]\n# 'Nun, aller h\u00f6here Humor f\u00e4ngt damit an, da\u00df man die eigene Person nicht mehr ernst nimmt.'\n\n>>> wikiquote.quote_of_the_day(lang='it')\n# \"Siamo angeli con un'ala sola. Possiamo volare solo restando abbracciati.\", 'Luciano De Crescenzo'\n\n>>> wikiquote.quote_of_the_day(lang='pl')\n# 'Bo\u017ce pom\u00f3\u017c mi by\u0107 takim cz\u0142owiekiem, za jakiego uwa\u017ca mnie m\u00f3j pies.', 'Janusz Leon Wi\u015bniewski'\n\n>>> wikiquote.quotes('Jos\u00e9 Saramago', lang='pt')[0]\n# 'Nem a juventude sabe o que pode, nem a velhice pode o que sabe.'\n```\n\nSpecifying an invalid language will result in an `UnsupportedLanguageException` exception.\n\n## Tips\nUse `random.choice()` to select a random quote from an article:\n```python\n>>> import wikiquote, random\n\n>>> random.choice(wikiquote.quotes('Linus Torvalds'))\n# 'WE DO NOT BREAK USERSPACE!'\n```\n\n## Caveats\nIn some cases, `wikiquote` may fail to retrieve quotes from some articles, or the quote of the day (QOTD). This is due to Wikiquote.org's varying internal article layouts: some quotes may be contained in `div` elements, others in `li`, etc. depending on the article and the language.\n\n## Developing\nFirst, make sure you have installed all necessary dependencies, including development dependencies:\n```bash\n$ pip install -r requirements-dev.txt -r requirements.txt\n```\n\nThen, check that all files are correctly formatted, and that the type hints are also correct:\n```bash\n$ make lint\n$ make types\n```\n\nAfter that, check that all tests pass:\n```bash\n$ make test\n```\nSome tests may be skipped in the QOTD is not available for some languages.\n\nFinally, create a pull request stating your changes.\n\n## Changelog\nSee the [CHANGELOG.md](CHANGELOG.md) file.\n\n## License\nThe `wikiquote` package is licensed under the MIT License.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Retrieve quotes from any Wikiquote article.",
    "version": "0.1.17",
    "project_urls": {
        "Download": "https://github.com/federicotdn/wikiquote/archive/0.1.17.tar.gz",
        "Homepage": "https://github.com/federicotdn/wikiquote"
    },
    "split_keywords": [
        "quotes",
        "wikiquote",
        "python",
        "api",
        "qotd",
        "quote",
        "day"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "36db403ca7d79e0719bfedb67e5a3f4b5de2d8b59bc9b9a7ce7a21eb47779d74",
                "md5": "51aa243d225319b392298a1f168a380d",
                "sha256": "4b2679f604875bac715d283d2c0ba128f87a63892ab4f4de7b501fd10699349c"
            },
            "downloads": -1,
            "filename": "wikiquote-0.1.17.tar.gz",
            "has_sig": false,
            "md5_digest": "51aa243d225319b392298a1f168a380d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8, <4",
            "size": 13359,
            "upload_time": "2023-08-20T12:50:49",
            "upload_time_iso_8601": "2023-08-20T12:50:49.154840Z",
            "url": "https://files.pythonhosted.org/packages/36/db/403ca7d79e0719bfedb67e5a3f4b5de2d8b59bc9b9a7ce7a21eb47779d74/wikiquote-0.1.17.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-20 12:50:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "federicotdn",
    "github_project": "wikiquote",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "wikiquote"
}
        
Elapsed time: 0.27248s