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

Version 1.1.0

parent 11097edd
# -*- coding: utf-8 -*-
# coding=utf-8
# Copyright 2019 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.
from datetime import datetime
from obelixtools import API
......@@ -26,39 +46,57 @@ URLS = {
class Law(object):
def __init__(self, data):
self.dateString = '%a, %d %b %Y %H:%M:%S GMT'
self.parse(data)
self.__data = 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 title(self):
return self.__data.find('title').text
@property
def description(self):
return self.__data.find('description').text
@property
def link(self):
return self.__data.find('link').text
@property
def guid(self):
return self.__data.find('guid').text
@property
def pubDate(self):
return datetime.strptime(self.__data.find('pubDate').text, self.dateString)
@property
def formatted(self):
"""Returns a formatted string with publication date, title and description."""
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
self.__data = data
@property
def title(self):
return self.__data.find('title').text
def parse(self, data):
self.title = data.find('title').text
@property
def description(self):
try: # WTF BMJV, some items do not have a description?
self.description = data.find('description').text
return self.__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
return 'Keine Beschreibung vorhanden'
@property
def pubDate(self):
return datetime.strptime(self.__data.find('pubDate').text[:-6], self.dateString)
@property
def formatted(self):
"""Returns a formatted string with publication date, title and description"""
return u'{} - {} - {}'.format(self.pubDate, self.title, self.description)
class BGBl(object):
......@@ -81,13 +119,21 @@ class BGBl(object):
return u'{} - {} - {}'.format(self.pubDate, self.title, self.description)
class RechtsprechungImInternet(object):
def __init__(self, id='bverfg'):
def __init__(self, id):
self.id = id
self.feed = self.selectCourt()
self.dateString = '%a, %d %b %Y %H:%M:%S GMT'
self.items = []
return
@property
def id(self):
return self.__id
@id.setter
def id(self, value):
self.__id = value if value else 'bverfg'
def selectCourt(self):
if self.id in URLS:
return API(url=URLS[self.id], format='xml')
......@@ -104,20 +150,3 @@ class RechtsprechungImInternet(object):
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] + '...')
# coding=utf-8
# Copyright 2019 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.
from datetime import datetime
from obelixtools import API
import logging, time
import argparse
from BMJV import *
if __name__ == '__main__':
logger = logging.getLogger(__name__)
parser = argparse.ArgumentParser()
parser.add_argument('--mode', choices=['bgbl', 'rim'], help='Seth mode.')
parser.add_argument('--court', type=str, default='bverfg', help='Select a court. Only relevant if in rim mode.')
parser.add_argument('--limit', type=int, default=0, help='Limit the number of results.')
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)
if args.mode == 'rim':
rim = RechtsprechungImInternet(args.court)
rim.fetch(args.limit)
for item in rim.items:
logger.info(item.formatted)
elif args.mode == 'bgbl':
gim = BGBl()
gim.fetch(args.limit)
for item in gim.items:
logger.info(item.formatted)
# coding=utf-8
# Copyright 2019 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.
import setuptools
with open("README.md", "r") as fh:
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",
name='BMJV',
version='1.1',
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",
long_description_content_type='text/markdown',
url='https://github.com/zkmkarlsruhe/pypi-bmjv',
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
python_requires='>=3.6',
install_requires=[
......
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