Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Extract league rankings from the DBB (Deutscher Basketball Bund e.V.) website.

Project Description

Extract league rankings from the DBB (Deutscher Basketball Bund e.V.) website.

This library has been extracted from the web application behind the website of the BTB Royals Oldenburg (a basketball team from Oldenburg, Germany) where it has proven itself for many, many years.

Requirements

Installation

Install this package via pip:

$ pip install dbb-ranking-parser

Because of the dependency on lxml, this will also require the header files for the targeted Python version as well as those for libxml2 and libxslt.

On Debian Linux, one should be able to install these from the distribution’s repositories (as the ‘root’ user):

# aptitude update
# aptitude install python3.4-dev libxml2-dev libxslt1-dev

Apart from that (for example, if those packages are not yet installed) it might be easier to install Debian’s pre-built binary packages for lxml instead:

# aptitude update
# aptitude install python-lxml

Usage

To fetch and parse a league ranking, the appropriate URL is required.

It can be obtained on the DBB website. On every league’s ranking page there should be a link to a (non-“XL”) HTML print version.

Its target URL should look like this (assuming the league’s ID is 12345): http://www.basketball-bund.net/public/tabelle.jsp?print=1&viewDescKey=sport.dbb.views.TabellePublicView/index.jsp_&liga_id=12345

The league ID has to be identified manually in any of the URLs specific for that league (ranking, schedule, stats).

For convenience, specifying only the league ID is sufficient; the URL will be assembled automatically. (Obviously, this might break when the URL structure changes on the DBB website.)

Programmatically

from dbbrankingparser import load_ranking_for_league


league_id = 12345

ranking = list(load_ranking_for_league(league_id))

top_team = ranking[0]
print('Top team:', top_team['name'])

The URL can be specified explicitly, too:

from dbbrankingparser import load_ranking_from_url


URL = '<see example above>'

ranking = list(load_ranking_from_url(URL))

Note that a call to a load_ranking_* method returns a generator. To keep its elements around, and also to access them by index, they can be fed into a list (as shown above).

On the Command Line

The package includes a command line script to retrieve a league’s rankings non-programmatically, as JSON. It requires a league ID as its sole argument:

$ dbb-ranking 12345
[{"name": "Team ACME", "rank": 1, …}]

Via HTTP

Also included is an HTTP wrapper around the parser.

To spin up the server:

$ dbb-ranking-server
Listening for HTTP requests on localhost:8080 ...

Since this is mostly meant to be used inside a Docker container, host and port are not (easily) configurable at this point.

The server will attempt to look up a ranking for requests with an URL part of the form /<league id>:

$ curl http://localhost:8080/12345
[{"name": "Team ACME", "rank": 1, …}]

Docker

The command line and HTTP server scripts can also be run in a Docker container each.

Building the respective Docker images requires:

  • Docker being installed
  • a source copy of the dbb-ranking-parser package

In the package path (as the ‘root’ user):

  • to build an image for the command line script:

    # docker build -t dbb-ranking-parser-cli ./docker/cli
    
  • to build an HTTP server image:

    # docker build -t dbb-ranking-parser-server ./docker/httpserver
    

Each of these commands should build a Docker image based upon Alpine Linux and which includes Python 3, lxml and the DBB Ranking Parser itself. It should be roughly 75 MB in size.

Running the command line script in a container requires the league ID as the sole argument:

# docker run --rm dbb-ranking-parser-cli 12345
[{"name": "Team ACME", "rank": 1, …}]

To spin up the HTTP server on port 8080:

# docker run -p 8080:8080 --rm dbb-ranking-parser-server

The --rm option causes a container (but not the image) to be removed after it exits.

Copyright:2006-2016 Jochen Kupperschmidt
Date:10-Mar-2016
License:MIT, see LICENSE for details.
Version:0.3.1
Website:http://homework.nwsnet.de/releases/4a51/#dbb-ranking-parser
Release History

Release History

This version
History Node

0.3.1

History Node

0.3

History Node

0.2

History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
dbb_ranking_parser-0.3.1-py2.py3-none-any.whl (11.9 kB) Copy SHA256 Checksum SHA256 3.4 Wheel Mar 10, 2016
dbb-ranking-parser-0.3.1.tar.gz (12.9 kB) Copy SHA256 Checksum SHA256 Source Mar 10, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting