HelloChatterbox / wikipedia_for_humans

Other
44 stars 5 forks source link

Get Wikipedia Link & Title #2

Closed sirquackiii closed 3 years ago

sirquackiii commented 3 years ago

I was wondering whether you can get the link of a Wikipedia article and its name from the article returned from wikipedia_for_humans.summary(). Is that possible? It would really be quite useful.

JarbasAl commented 3 years ago

try version 0.2.2 which adds two new methods, images and page_data

for your use case

import wikipedia_for_humans

data = wikipedia_for_humans.page_data("quantum mechanics")
title = data["title"]
url = data["url"]

where data is


{'categories': ['Articles with separate introductions',
                'Articles with short description',
                'CS1 German-language sources (de)',
                'Pages using Sister project links with default search',
                'Quantum mechanics',
                'Short description is different from Wikidata',
                'Wikipedia articles with BNF identifiers',
                'Wikipedia articles with GND identifiers',
                'Wikipedia articles with LCCN identifiers',
                'Wikipedia articles with NDL identifiers',
                'Wikipedia articles with NKC identifiers',
                'Wikipedia articles with SUDOC identifiers',
                'Wikipedia indefinitely semi-protected pages'],
 'images': ['https://upload.wikimedia.org/wikipedia/commons/e/e7/Hydrogen_Density_Plots.png'],
 'lang': 'en',
 'page_id': 25202,
 'sections': [{'text': 'Quantum mechanics allows the calculation of '
                       'probabilities for how physical systems can behave. It '
                       'is typically applied to microscopic systems: '
                       'molecules, atoms and sub-atomic particles. Predictions '
                       'of quantum mechanics have been verified experimentally '
                       'to an extremely high degree of accuracy. A basic '
                       'mathematical feature of quantum mechanics is that a '
                       ' (...) '
                       'developments include string theory and other attempts '
                       'to build a quantum theory of gravity.',
               'title': 'History'}],
 'summary': 'Quantum mechanics is a fundamental theory in physics that '
            'provides a description of the physical properties of nature at '
            'the scale of atoms and subatomic particles. It is the foundation '
            'of all quantum physics including quantum chemistry, quantum field '
            'theory, quantum technology, and quantum information science.\n'
            'Classical physics, the description of physics that existed before '
            'the theory of relativity and quantum mechanics, describes many '
            'aspects of nature at an ordinary (macroscopic) scale, while '
            'quantum mechanics explains the aspects of nature at small (atomic '
            'and subatomic) scales, for which classical mechanics is '
            'insufficient. Most theories in classical physics can be derived '
            'from quantum mechanics as an approximation valid at large '
            '(macroscopic) scale.Quantum mechanics differs from classical '
            'physics in that energy, momentum, angular momentum, and other '
            'quantities of a bound system are restricted to discrete values '
            '(quantization), objects have characteristics of both particles '
            'and waves (wave-particle duality), and there are limits to how '
            'accurately the value of a physical quantity can be predicted '
            'prior to its measurement, given a complete set of initial '
            'conditions (the uncertainty principle).\n'
            'Quantum mechanics arose gradually from theories to explain '
            'observations which could not be reconciled with classical '
            "physics, such as Max Planck's solution in 1900 to the black-body "
            'radiation problem, and the correspondence between energy and '
            "frequency in Albert Einstein's 1905 paper which explained the "
            'photoelectric effect. These early attempts to understand '
            'microscopic phenomena, now known as the "old quantum theory", led '
            'to the full development of quantum mechanics in the mid-1920s by '
            'Niels Bohr, Erwin Schrödinger, Werner Heisenberg, Max Born and '
            'others. The modern theory is formulated in various specially '
            'developed mathematical formalisms. In one of them, a mathematical '
            'entity called the wave function provides information, in the form '
            'of probability amplitudes, about what measurements of a '
            "particle's energy, momentum, and other physical properties may "
            'yield.',
 'title': 'Quantum mechanics',
 'url': 'https://en.wikipedia.org/wiki/Quantum_mechanics'}