Skip to content

Commit

Permalink
0.3.5 (#10)
Browse files Browse the repository at this point in the history
* Add documentation to README
  * Quickstart information
  * pip install instructions [pypi - pymediawiki](https://pypi.python.org/pypi/pymediawiki/)
* Additional testing
  • Loading branch information
barrust committed Oct 15, 2016
1 parent 0817380 commit 901fd88
Show file tree
Hide file tree
Showing 10 changed files with 3,334 additions and 2,539 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,14 @@

## Current

### Version 0.3.5

* Add documentation to README
* Quickstart information
* pip install instructions [pypi - pymediawiki](https://pypi.python.org/pypi/pymediawiki/)
* Additional testing


### Version 0.3.4

* Update documentation
Expand Down
81 changes: 70 additions & 11 deletions README.rst
@@ -1,5 +1,17 @@
MediaWiki
=========
.. image:: https://travis-ci.org/barrust/mediawiki.svg?branch=master
:target: https://travis-ci.org/barrust/mediawiki
.. image:: https://coveralls.io/repos/github/barrust/mediawiki/badge.svg
:target: https://coveralls.io/github/barrust/mediawiki
.. image:: https://www.quantifiedcode.com/api/v1/project/91ebef7368ca4669aac81c45c48cc2a9/badge.svg
:target: https://www.quantifiedcode.com/app/project/91ebef7368ca4669aac81c45c48cc2a9
:alt: Code issues
.. image:: https://api.codacy.com/project/badge/Grade/afa87d5f5b6e4e66b78e15dedbc097ec
:target: https://www.codacy.com/app/barrust/mediawiki?utm_source=github.com&utm_medium=referral&utm_content=barrust/mediawiki&utm_campaign=Badge_Grade
.. image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://opensource.org/licenses/MIT/
:alt: License

**mediawiki** is a python wrapper for the MediaWiki API. The goal is to allow
users to quickly and efficiently pull data from the MediaWiki site of their
Expand All @@ -20,7 +32,16 @@ be considerate of the MediaWiki infrastructure.

Installation
------------------
To installing `mediawiki`, simply clone the `repository on GitHub

Pip Installation:

::

$ pip install pymediawiki

To install from source:

To install `mediawiki`, simply clone the `repository on GitHub
<https://github.com/barrust/mediawiki>`__, then run from the folder:

::
Expand All @@ -29,29 +50,67 @@ To installing `mediawiki`, simply clone the `repository on GitHub

`mediawiki` supports python versions 2.7 and 3.3 - 3.5

In the future, it would be great if `mediawiki` were available to install
using pip!
Documentation
-------------

Documentation of the latest release is hosted on
`pythonhosted.org <https://pythonhosted.org/pymediawiki/>`__

To build the documentation yourself run:

::

$ pip install sphinx
$ cd docs/
$ make html

Automated Tests
------------------

To run automated tests, one must simply run the following command from the
downloaded folder:

::

$ python setup.py test
$ python setup.py test

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

To build the documentation yourself run:
Quickstart
------------------

Import mediawiki and run a standard search against Wikipedia:

.. code:: python
>>> from mediawiki import MediaWiki
>>> wikipedia = MediaWiki()
>>> wikipedia.search('washington')
Run more advanced searches:

.. code:: python
>>> wikipedia.opensearch('washington')
>>> wikipedia.geosearch(title='washington, d.c.')
>>> wikipedia.geosearch(latitude='0.0', longitude='0.0')
>>> wikipedia.prefixsearch('arm')
>>> wikipedia.random(pages=10)
Pull a MediaWiki page and some of the page properties:

.. code:: python
>>> p = wikipedia.page('Chess')
>>> p.title
>>> p.summary
>>> p.categories
>>> p.images
>>> p.links
See the
`Documentation for more examples! <https://pythonhosted.org/pymediawiki/>`__

::

$ pip install sphinx
$ cd docs/
$ make html

Changelog
------------------
Expand Down
7 changes: 4 additions & 3 deletions docs/source/conf.py
Expand Up @@ -22,6 +22,7 @@
#sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../../'))
sys.path.append(os.path.abspath('_themes'))
import mediawiki

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -57,16 +58,16 @@
# General information about the project.
project = 'mediawiki'
copyright = '2016, Tyler Barrus'
author = 'Tyler Barrus'
author = mediawiki.__author__

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.3.4'
version = mediawiki.__version__
# The full version, including alpha/beta/rc tags.
release = '0.3.4'
release = mediawiki.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
35 changes: 17 additions & 18 deletions mediawiki/mediawiki.py
Expand Up @@ -11,14 +11,14 @@
from decimal import (Decimal, DecimalException)
import requests
from bs4 import BeautifulSoup
from .exceptions import (MediaWikiBaseException, MediaWikiException, PageError,
from .exceptions import (MediaWikiException, PageError,
RedirectError, DisambiguationError,
MediaWikiAPIURLError, HTTPTimeoutError,
MediaWikiGeoCoordError, ODD_ERROR_MESSAGE)
from .utilities import memoize

URL = 'https://github.com/barrust/mediawiki'
VERSION = '0.3.4'
VERSION = '0.3.5'


class MediaWiki(object):
Expand All @@ -35,7 +35,7 @@ class MediaWiki(object):
:type rate_limit: Boolean
:param rate_limit_wait: Amount of time to wait between requests
:type rate_limit_wait: timedelta
'''
'''

def __init__(self, url='http://en.wikipedia.org/w/api.php', lang='en',
timeout=None, rate_limit=False,
Expand Down Expand Up @@ -452,7 +452,6 @@ def prefixsearch(self, prefix, results=10):
self._check_query(prefix, 'Prefix must be specified')

query_params = {
'action': 'query',
'list': 'prefixsearch',
'pssearch': prefix,
'pslimit': ('max' if results > 500 else results),
Expand Down Expand Up @@ -583,7 +582,7 @@ def page(self, title=None, pageid=None, auto_suggest=True, redirect=True,
.. note:: Title takes precedence over pageid if both are provided
'''
if (title is None or title.strip() == '') and pageid is None:
raise ValueError('Title or Pageid must be specified')
raise ValueError('Either a title or a pageid must be specified')
elif title:
if auto_suggest:
temp_title = self.suggest(title)
Expand Down Expand Up @@ -620,16 +619,12 @@ def wiki_request(self, params):
wait_time = (last_call + self._min_wait) - datetime.now()
time.sleep(int(wait_time.total_seconds()))

if self._session is None:
self._reset_session()

req = self._session.get(self._api_url, params=params,
timeout=self._timeout)
req = self._get_response(params)

if self._rate_limit:
self._rate_limit_last_call = datetime.now()

return req.json(encoding='utf8')
return req
# end wiki_request

# Protected functions
Expand Down Expand Up @@ -681,6 +676,12 @@ def _check_query(value, message):
''' check if the query is 'valid' '''
if value is None or value.strip() == '':
raise ValueError(message)

def _get_response(self, params):
''' wrap the call to the requests package '''
return self._session.get(self._api_url, params=params,
timeout=self._timeout).json(encoding='utf8')

# end MediaWiki class


Expand Down Expand Up @@ -727,14 +728,12 @@ def __init__(self, mediawiki, title=None, pageid=None,

self.__load(redirect=redirect, preload=preload)

if preload:
for prop in ('content', 'summary', 'images', 'references', 'links',
preload_props = ['content', 'summary', 'images', 'references', 'links',
'sections', 'redirects', 'coordinates', 'backlinks',
'categories'):
try:
getattr(self, prop)
except MediaWikiBaseException:
pass
'categories']
if preload:
for prop in preload_props:
getattr(self, prop)
# end __init__

def __repr__(self):
Expand Down
5 changes: 1 addition & 4 deletions mediawiki/utilities.py
Expand Up @@ -11,10 +11,7 @@ def memoize(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
''' wrap it up and store info in a cache '''
# add it to the class if needed
if not hasattr(args[0], '_cache'):
args[0]._cache = dict()
cache = args[0]._cache
cache = args[0].memoized
if func.__name__ not in cache:
cache[func.__name__] = dict()
# build a key; should also consist of the default values
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
@@ -0,0 +1,2 @@
[bdist_wheel]
universal=1
11 changes: 5 additions & 6 deletions setup.py
Expand Up @@ -3,30 +3,29 @@
'''
import setuptools

import sys
sys.dont_write_bytecode = True

from mediawiki import (__version__, __author__, __license__, __email__,
__url__)

setuptools.setup(
name = 'mediawiki',
name = 'pymediawiki', # mediawiki was taken
version = __version__,
author = __author__,
author_email = __email__,
description = 'MediaWiki API for Python',
license = __license__,
keywords = 'python mediawiki wikipedia API',
url = __url__,
download_url = '{0}/tarball/v{1}'.format(__url__, __version__),
install_requires = ['beautifulsoup4', 'requests>=2.0.0,<3.0.0'],
packages = ['mediawiki'],
long_description = 'NEED TO WRITE A LONG DESCRIPTION',
long_description = open('README.rst', 'r').read(),
classifiers = [
'Development Status :: 4 - Beta',
'Topic :: Software Development :: Libraries',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3'
],
test_suite='tests'
test_suite = 'tests',
test_requires = ['unittest']
)

0 comments on commit 901fd88

Please sign in to comment.