Skip to main content

Wikipedia revision history parser for Python

Project description

WikiRevParser

WikiRevParser is a Python library that parses Wikipedia revision histories and allows you to analyse the development of pages on Wikipedia across all language versions.

The library extracts and parses Wikipedia revision histories from a language-page title pair and outputs clean, accessible data per timestamp in the revision history. You can use this library to access the development of references of a page, analyse the content or images over time, compare the tables of content across languages, create editor networks, and much more.

Example

To get the revision history for the page on Marie Curie on the English Wikipedia, run:

>>> from wikirevparser import wikirevparser
>>> parser_instance = wikirevparser.ProcessRevisions("en", "Marie Curie") 
>>> parser_instance.wikipedia_page()
>>> data = parser_instance.parse_revisions()

And you can access information like these:

about links:

>>> edits = list(data.items())
>>> first_links = edits[-1][1]["links"]
>>> latest_links = edits[0][1]["links"]
>>> print("Number of links in the first edit: %d." % len(first_links))
Number of links in the first edit: 1. 
>>> print("A link in the first edit: %s." % first_links[0])
A link in the first edit: pierre and marie curie. 
>>> print("Number of links in the latest edit: %d." % len(latest_links))
Number of links in the latest edit: 320. 
>>> print("A link in the latest edit: %s." % latest_links[0])
A link in the first edit: congress poland.

about editors:

>>> from collections import Counter
>>> editors = Counter()
>>> for timestamp in data:
>>>	  editors[data[timestamp]["user"]] += 1
>>> most_frequent = editors.most_common(1)[0]
>>> editor, edits = most_frequent[0], most_frequent[1]
>>> print("%s has edited the page the most, all of %d times (%d percent)!" % (editor, edits, (edits/len(data)*100)))
Nihil novi has edited the page the most, all of 619 times (13 percent)!

You could also investigate the use of images, the changes in tables of content, analyse differences across different language versions, and much, much more.

Installation

To install WikiRevParser, you can clone the repository on GitHub or simply run:

>>> pip3 install wikirevparser

Requirements

The WikiRevParser requires Python 3+.

You'll also need a few common Python libraries as well as our Wikipedia API wrapper (forked from Wikipedia by @goldsmith), which extracts and returns the entire revision history of a Wikipedia page.

Run the following to install all requirements needed:

>>> python3 install -r requirements.txt
>>> git clone git@github.com:ajoer/Wikipedia.git

The first command installs all requirements specified in the requirements.txt file, and the second command clones our version of the Wikipedia API wrapper needed for revision history extraction.

Documentation

Read the docs at readthedocs.io

License

This work is MIT licensed. See the LICENSE file for full details.

Credits

  • @goldsmith for the Python Wikipedia API wrapper Wikipedia.
  • The Wikimedia Foundation and all Wikipedians for creating and maintaining the data.
  • This work has received funding from the European Union’s Horizon 2020 research and innovation programme under the Marie Skłodowska-Curie grant agreement No. 812997.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wikirevparser-0.0.4.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

wikirevparser-0.0.4-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file wikirevparser-0.0.4.tar.gz.

File metadata

  • Download URL: wikirevparser-0.0.4.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for wikirevparser-0.0.4.tar.gz
Algorithm Hash digest
SHA256 2e37db6576689687eb99af5c68e3e8ee1e841cc261eb86749511bd18f1f7d1a1
MD5 5878978070b67c57d51fbe0455e53c18
BLAKE2b-256 cd50e2f441ef48701f0efe1f0d03aeaca211535001681f845827c1055cba2f76

See more details on using hashes here.

File details

Details for the file wikirevparser-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: wikirevparser-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for wikirevparser-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cc4ddf116e32b1d87843d87e52bd3c6001af06f013db6a9e773f1ef0d7d89493
MD5 2edac45e219de41842feede112615d41
BLAKE2b-256 4af06810b8bb843a81ed1b4eaba06b5495d645aad4bf0b4955962c0dd066c81a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page