Package: wikiquote
wikiquoteThewikiquotepackage for Python (>=3.8) allows you to search and retrieve quotes from anyWikiquotearticle, as well as retrieve the quote of the day.InstallationYou can install thewikiquotepackage usingpip:$pipinstall--upgradewikiquoteUsage>>>importwikiquote>>>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 (likeMatrix), which will raise aDisambiguationPageExceptionexception. Usually this happens because there are many articles matching the search term. When this happens, try usingsearch()first, and then use one of the specific article titles found.If the article searched for does not exist, and no similar results exist,NoSuchPageExceptionwill be raised instead.When requesting the quote of the day, aMissingQOTDExceptionexception 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.LanguagesThewikiquotemodule currently supports the following languages:LanguageISO 639-1 CodeBasqueeuEnglishenFrenchfrGermandeHebrewheItalianitPolishplPortugueseptSpanishesUse thelangparameter to specify the language (defaults toen):>>>importwikiquote>>>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 anUnsupportedLanguageExceptionexception.TipsUserandom.choice()to select a random quote from an article:>>>importwikiquote,random>>>random.choice(wikiquote.quotes('Linus Torvalds'))# 'WE DO NOT BREAK USERSPACE!'CaveatsIn some cases,wikiquotemay 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 indivelements, others inli, etc. depending on the article and the language.DevelopingFirst, make sure you have installed all necessary dependencies, including development dependencies:$pipinstall-rrequirements-dev.txt-rrequirements.txtThen, check that all files are correctly formatted, and that the type hints are also correct:$makelint
$maketypesAfter that, check that all tests pass:$maketestSome tests may be skipped in the QOTD is not available for some languages.Finally, create a pull request stating your changes.ChangelogSee theCHANGELOG.mdfile.LicenseThewikiquotepackage is licensed under the MIT License.