Package: dbb-ranking-parser
DBB Ranking ParserExtract league rankings from theDBB(Deutscher Basketball Bund e.V.)
website.This library has been extracted from the web application behind the
website of theBTB Royals Oldenburg(a basketball team from
Oldenburg, Germany) where it has proven itself for many, many years.RequirementsPython3.6+lxmlInstallationInstall this package viapip:$pipinstalldbb-ranking-parserBecause of the dependency onlxml, this will also require the header
files for the targetedPythonversion as well as those forlibxml2andlibxslt.OnDebian Linux, one should be able to install these from the
distribution’s repositories (as the ‘root’ user):# aptitude update
# aptitude install python3.7-dev libxml2-dev libxslt1-devApart from that (for example, if those packages are not yet installed)
it might be easier to install Debian’s pre-built binary packages forlxmlinstead:# aptitude update
# aptitude install python-lxmlUsageTo fetch and parse a league ranking, the appropriate URL is required.It can be obtained on theDBBwebsite. 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=12345The 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.)Programmaticallyfromdbbrankingparserimportload_ranking_for_leagueleague_id=12345ranking=list(load_ranking_for_league(league_id))top_team=ranking[0]print('Top team:',top_team['name'])The URL can be specified explicitly, too:fromdbbrankingparserimportload_ranking_from_urlURL='<see example above>'ranking=list(load_ranking_from_url(URL))Note that a call to aload_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 LineThe 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-parserget12345[{"name":"Team ACME","rank":1,…}]Via HTTPAlso included is an HTTP wrapper around the parser.To spin up the server:$dbb-ranking-parserserveListeningforHTTPrequestson127.0.0.1:8080...The server will attempt to look up a ranking for requests with an URL
part of the form/<league id>:$curlhttp://localhost:8080/12345[{"name":"Team ACME","rank":1,…}]DockerDBB Ranking Parser can also be run in aDockercontainer. This avoids
the local creation of a virtual environment and the installation of the
packages, or be useful in a deployment where containers are used.Building aDockerimage requires:Dockerbeing installeda source copy of thedbb-ranking-parserpackageIn the package path:$dockerbuild-tdbb-ranking-parser.This should build aDockerimage based uponAlpine Linuxand which
includesPython3,lxmland the DBB Ranking Parser itself. It should
be roughly 70 MB in size.Running the Docker container accepts the same arguments as the command
line script.To fetch a single ranking:$dockerrun--rmdbb-ranking-parserget12345[{"name":"Team ACME","rank":1,…}]To spin up the HTTP server on port 7000 of the host machine:$dockerrun-p7000:8080--rmdbb-ranking-parserserve--host0.0.0.0--port8080The--rmoption causes a container (but not the image) to be removed
after it exits.Copyright:2006-2021 Jochen KupperschmidtLicense:MIT, see LICENSE for details.Website:http://homework.nwsnet.de/releases/4a51/#dbb-ranking-parserDBB Ranking Parser ChangelogVersion 0.4.2Released on February 20, 2021Fixed description of how to run the HTTP server in a Docker container.Version 0.4.1Released on February 13, 2021Fixed reStructuredText issues in changelog which prevented a release
on PyPI.Version 0.4Released on February 13, 2021Added support for Python 3.6, 3.7, 3.8, and 3.9.Dropped support for Python 3.4 and 3.5 (which are end-of-life).Updated lxml to at least version 4.6.2.Moved package metadata fromsetup.pytosetup.cfg.Switched to asrc/project layout.Added type hints (PEP 484).Ported tests fromunittestto pytest.Merged basic and HTTP server command line interfaces into a single
argument parser with subcommandsgetandserve. Removeddbb-ranking-serverentrypoint.Renamed command line entrypoint todbb-ranking-parser.Added command line option--versionto show the application’s
version.Merged the previous threeDockerfilefiles into a single one.Updated and simplified Docker image and build process by upgrading
Alpine Linux to 3.13 and installing lxml as a binary package,
removing the need for local compilation.Version 0.3.1Released March 10, 2016Allowed to specify the HTTP server’s host and port on the command
line.FixedDockerfilefor the HTTP server to bind it to a public address
instead of localhost so that exposing the port actually works.Version 0.3Released March 8, 2016Added HTTP server that wraps the parser and responds with rankings as
JSON.AddedDockerfilefiles for the command line script and the HTTP
server.Version 0.2Released March 6, 2016It is now sufficient to specify just the league ID instead of the full
URL. The latter is still possible, though.Added a command line script to retrieve a league’s ranking as JSON.Return nothing when parsing irrelevant HTML table rows.Return extracted ranks as a generator instead of a list.Split code over several modules.Version 0.1Released March 5, 2016first official release