Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 11 additions & 67 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,48 +1,19 @@
Wikipedia
=========

.. image:: https://travis-ci.org/goldsmith/Wikipedia.png?branch=master
:target: https://travis-ci.org/goldsmith/Wikipedia
.. image:: https://pypip.in/d/wikipedia/badge.png
:target: https://crate.io/packages/wikipedia
.. image:: https://pypip.in/v/wikipedia/badge.png
:target: https://crate.io/packages/wikipedia
.. image:: https://pypip.in/license/wikipedia/badge.png
:target: https://pypi.python.org/pypi/wikipedia/
:alt: License

**Wikipedia** is a Python library that makes it easy to access and parse
Wikipedia with sections
=======================

**Wikipedia with sections** is a Python library that makes it easy to access and parse
data from Wikipedia.

Search Wikipedia, get article summaries, get data like links and images
from a page, and more. Wikipedia wraps the `MediaWiki
API <https://www.mediawiki.org/wiki/API>`__ so you can focus on using
Wikipedia data, not getting it.
This is a fork from Jonathan Goldsmith's `Wikipedia package <https://github.com/goldsmith/Wikipedia>`__

.. code:: python

>>> import wikipedia
>>> print wikipedia.summary("Wikipedia")
# Wikipedia (/ˌwɪkɨˈpiːdiə/ or /ˌwɪkiˈpiːdiə/ WIK-i-PEE-dee-ə) is a collaboratively edited, multilingual, free Internet encyclopedia supported by the non-profit Wikimedia Foundation...

>>> wikipedia.search("Barack")
# [u'Barak (given name)', u'Barack Obama', u'Barack (brandy)', u'Presidency of Barack Obama', u'Family of Barack Obama', u'First inauguration of Barack Obama', u'Barack Obama presidential campaign, 2008', u'Barack Obama, Sr.', u'Barack Obama citizenship conspiracy theories', u'Presidential transition of Barack Obama']

>>> ny = wikipedia.page("New York")
>>> ny.title
# u'New York'
>>> ny.url
# u'http://en.wikipedia.org/wiki/New_York'
>>> ny.content
# u'New York is a state in the Northeastern region of the United States. New York is the 27th-most exten'...
>>> ny.links[0]
# u'1790 United States Census'

>>> wikipedia.set_lang("fr")
>>> wikipedia.summary("Facebook", sentences=1)
# Facebook est un service de réseautage social en ligne sur Internet permettant d'y publier des informations (photographies, liens, textes, etc.) en contrôlant leur visibilité par différentes catégories de personnes.
>>> ny.sections[:5]
# ['Etymology', 'History', 'Early history', 'Dutch rule', 'English rule']

Note: this library was designed for ease of use and simplicity, not for advanced use. If you plan on doing serious scraping or automated requests, please use `Pywikipediabot <http://www.mediawiki.org/wiki/Manual:Pywikipediabot>`__ (or one of the other more advanced `Python MediaWiki API wrappers <http://en.wikipedia.org/wiki/Wikipedia:Creating_a_bot#Python>`__), which has a larger API, rate limiting, and other features so we can be considerate of the MediaWiki infrastructure.

Installation
------------
Expand All @@ -51,56 +22,29 @@ To install Wikipedia, simply run:

::

$ pip install wikipedia
$ pip install wikipedia_sections

Wikipedia is compatible with Python 2.6+ (2.7+ to run unittest discover) and Python 3.3+.

Documentation
-------------

Read the docs at https://wikipedia.readthedocs.org/en/latest/.

- `Quickstart <https://wikipedia.readthedocs.org/en/latest/quickstart.html>`__
- `Full API <https://wikipedia.readthedocs.org/en/latest/code.html>`__

To run tests, clone the `repository on GitHub <https://github.com/goldsmith/Wikipedia>`__, then run:

::

$ pip install -r requirements.txt
$ bash runtests # will run tests for python and python3
$ python -m unittest discover tests/ '*test.py' # manual style

in the root project directory.

To build the documentation yourself, after installing requirements.txt, run:

::

$ pip install sphinx
$ cd docs/
$ make html
See https://github.com/goldsmith/Wikipedia for full dcumentation.

License
-------

MIT licensed. See the `LICENSE
file <https://github.com/goldsmith/Wikipedia/blob/master/LICENSE>`__ for
file <https://github.com/sachavakili/Wikipedia/blob/master/LICENSE>`__ for
full details.

Credits
-------

- `Wikipedia <https://github.com/goldsmith/Wikipedia>`__ by Jonathan Goldsmith for the original repository
- `wiki-api <https://github.com/richardasaurus/wiki-api>`__ by
@richardasaurus for inspiration
- @nmoroze and @themichaelyang for feedback and suggestions
- The `Wikimedia
Foundation <http://wikimediafoundation.org/wiki/Home>`__ for giving
the world free access to data



.. image:: https://d2weczhvl823v0.cloudfront.net/goldsmith/wikipedia/trend.png
:alt: Bitdeli badge
:target: https://bitdeli.com/free

13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def local_file(file):


setuptools.setup(
name = "wikipedia",
name = "wikipedia_sections",
version = '.'.join(version),
author = "Jonathan Goldsmith",
author_email = "jhghank@gmail.com",
description = "Wikipedia API for Python",
author = "Sacha Vakili",
author_email = "vakili.sacha@gmail.com",
description = "Wikipedia API for Python extracting sections",
license = "MIT",
keywords = "python wikipedia API",
url = "https://github.com/goldsmith/Wikipedia",
url = "https://github.com/sachavakili/Wikipedia",
install_requires = install_reqs,
packages = ['wikipedia'],
long_description = local_file('README.rst').read(),
Expand All @@ -41,5 +41,6 @@ def local_file(file):
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3'
]
],
download_url='https://github.com/sachavakili/Wikipedia/archive/v2.0.tar.gz',
)
2 changes: 1 addition & 1 deletion wikipedia/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .wikipedia import *
from .exceptions import *

__version__ = (1, 4, 0)
__version__ = (2, 0, 0)
4 changes: 0 additions & 4 deletions wikipedia/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,13 +735,9 @@ def _wiki_request(params):
wait_time = (RATE_LIMIT_LAST_CALL + RATE_LIMIT_MIN_WAIT) - datetime.now()
time.sleep(int(wait_time.total_seconds()))

print(f"GET request: {params}")

r = requests.get(API_URL, params=params, headers=headers)

if RATE_LIMIT:
RATE_LIMIT_LAST_CALL = datetime.now()

print(f"GET response: {r.json()}")

return r.json()