Commit 11097edd authored by loelkes's avatar loelkes Committed by Christian Lölkes
Browse files

Version 1.0.0

parents
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# -*- coding: utf-8 -*-
from datetime import datetime
from obelixtools import API
import logging, time
logger = logging.getLogger(__name__)
URLS = {
# Rechtssprechung des Bundesverfassungsgerichts
'bverfg': 'https://www.rechtsprechung-im-internet.de/jportal/docs/feed/bsjrs-bverfg.xml',
# Rechtsprechung des Bundesgerichtshofs
'bgh': 'https://www.rechtsprechung-im-internet.de/jportal/docs/feed/bsjrs-bgh.xml',
# Rechtsprechung des Bundesverwaltungsgerichts
'bverwg': 'https://www.rechtsprechung-im-internet.de/jportal/docs/feed/bsjrs-bverwg.xml',
# Rechtsprechung des Bundesfinanzhofs
'bfh': 'https://www.rechtsprechung-im-internet.de/jportal/docs/feed/bsjrs-bfh.xml',
# Rechtssprechung des Bundesarbeitsgerichts
'bag': 'https://www.rechtsprechung-im-internet.de/jportal/docs/feed/bsjrs-bag.xml',
# Rechtssprechung des Bundessoszialgerichts
'bsg': 'https://www.rechtsprechung-im-internet.de/jportal/docs/feed/bsjrs-bsg.xml',
# Rechtssprechung des Bundespatengerichts
'bpatg': 'https://www.rechtsprechung-im-internet.de/jportal/docs/feed/bsjrs-bpatg.xml'
}
class Law(object):
def __init__(self, data):
self.dateString = '%a, %d %b %Y %H:%M:%S GMT'
self.parse(data)
return
def parse(self, data):
self.title = data.find('title').text
self.description = data.find('description').text
self.link = data.find('link').text
self.guid = data.find('guid').text
self.pubDate = datetime.strptime(data.find('pubDate').text, self.dateString)
return
@property
def formatted(self):
return u'{} - {} - {}'.format(self.pubDate, self.title, self.description)
class Judicature(object):
def __init__(self, data):
self.dateString = '%d %b %Y %H:%M:%S'
self.parse(data)
return
def parse(self, data):
self.title = data.find('title').text
try: # WTF BMJV, some items do not have a description?
self.description = data.find('description').text
except:
self.description = 'Keine Beschreibung vorhanden'
# TODO: Better Parsing of Datetime string possible?
self.pubDate = datetime.strptime(data.find('pubDate').text[:-6], self.dateString)
return
@property
def formatted(self):
return u'{} - {} - {}'.format(self.pubDate, self.title, self.description)
class BGBl(object):
def __init__(self, url=False):
self.url = url or 'https://www.gesetze-im-internet.de/aktuDienst-rss-feed.xml'
self.feed = API(url=self.url, format='xml')
def fetch(self, limit=0):
self.feed.query()
self.items = []
for item in self.feed.content[0].findall('item'):
self.items.append(Law(item))
self.items = sorted(self.items, key=lambda item: item.pubDate)
if limit:
self.items = self.items[:limit]
self.lastRefresh = time.time()
@property
def formatted(self):
return u'{} - {} - {}'.format(self.pubDate, self.title, self.description)
class RechtsprechungImInternet(object):
def __init__(self, id='bverfg'):
self.id = id
self.feed = self.selectCourt()
self.dateString = '%a, %d %b %Y %H:%M:%S GMT'
self.items = []
return
def selectCourt(self):
if self.id in URLS:
return API(url=URLS[self.id], format='xml')
else:
return False
def fetch(self, limit=0):
self.feed.query()
self.items = []
for entry in self.feed.content[0].findall('item'):
self.items.append(Judicature(entry))
self.items = sorted(self.items, key=lambda law: law.pubDate)
if limit:
self.items = self.items[:limit]
self.lastRefresh = time.time()
logger.info('Found a total of {} results for {}'.format(len(self.items), self.id))
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
logger.info('Script is executed as standalone file.')
logger.info('Fetching information from all court endoints...')
for id, url in URLS.items():
rim = RechtsprechungImInternet(id)
rim.fetch(2)
for item in rim.items:
logger.info(item.formatted[:100] + '...')
logger.info('Fetching information from legistation endoint...')
gim = BGBl()
gim.fetch(2)
for item in gim.items:
logger.info(item.formatted[:100] + '...')
Copyright 2017 Christian Lölkes
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# BMJV
*Note:* This a pathon wrapper around the data feeds from the Federal Ministry of Justice and Consumer Protection in Germany. It's content is exclusivly in German. Please see [Translations](https://www.gesetze-im-internet.de/Teilliste_translations.html) on the website of the ministry for further information.
**BMJV** stands for **B**undes**m**inisterium der **J**ustiz und für **V**erbraucherschutz (Federal Ministry of Justice and Consumer Protection).
# Installation
1. Install it with ```pip install bmjv```
## Usage
1. ```from BMJV import BGBl, RechtsprechungImInternet```
### Rechtsprechung im Internet
The latest rulings from the seven major german courts.
```foobar = RechtsprechungImInternet( id )```
```id``` can be used to select a special court. It is optional and set to *bverfg* by default.
* *bverfg*: Bundesverfassungsgericht
* *bgh*: Bundesgerichtshof
* *bverwg*: Bundesverwaltungsgericht
* *bfh*: Bundesfinanzhof
* *bag*: Bundesarbeitsgericht
* *bsg*: Bundessoszialgericht
* *bpatg*: Bundespatengericht
All results are stored in a list at ```foobar.items```. Each item is a *Judicature* with the following attributes:
* ```.title``` : The title as string.
* ```.description``` : The description string.
* ```.pubdate``` : The publication as datetime object.
### Gesetze im Internet
The latest laws published by the german government in the Bundesgesetzblatt (BGBl).
```foobar = BGBl()```
All results are stored in a list at ```foobar.items```. Each item is a *Law* with the following attributes:
* ```.title``` : The title as string.
* ```.description``` : The description string.
* ```.pubdate``` : The publication as datetime object.
## Data sources
* [Gesetze im Internet](https://www.gesetze-im-internet.de/)
* [Rechtsprechung im Internet](https://www.rechtsprechung-im-internet.de/)
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="BMJV",
version="1.0",
author="Christian Lölkes",
author_email="christian.loelkes@gmail.com",
description="Data from the Federal Ministry of Justice and Consumer Protection",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://hertz-gitlab.zkm.de/rapid-prototyping-lab/python-modules/bmjv",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
install_requires=[
'obelixtools'
],
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment