From 221d1ab9643cf909f45e585b4c8140c0e6b881248afe72335fe516fd56853379 Mon Sep 17 00:00:00 2001 From: Falco Duersch Date: Wed, 26 Sep 2018 16:14:35 +0200 Subject: [PATCH] Cleanup: remove tiny 'canteen' module, document main entry points --- stw_potsdam/canteen.py | 6 ------ stw_potsdam/canteen_api.py | 10 +++++++++- stw_potsdam/config.py | 10 +++++++++- stw_potsdam/feed.py | 10 ++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) delete mode 100644 stw_potsdam/canteen.py diff --git a/stw_potsdam/canteen.py b/stw_potsdam/canteen.py deleted file mode 100644 index 07f85d8..0000000 --- a/stw_potsdam/canteen.py +++ /dev/null @@ -1,6 +0,0 @@ -# -*- encoding: utf-8 -*- - -from collections import namedtuple - -Canteen = namedtuple('Canteen', - ('key', 'name', 'street', 'city', 'id', 'chash')) diff --git a/stw_potsdam/canteen_api.py b/stw_potsdam/canteen_api.py index a1f3bf7..f2a2806 100644 --- a/stw_potsdam/canteen_api.py +++ b/stw_potsdam/canteen_api.py @@ -11,11 +11,19 @@ URL = 'https://www.studentenwerk-potsdam.de' + \ def _param_json(to_serialize): - """Obtain JSON string of an object without whitespace on delimiters.""" + """Obtain JSON string of an object without whitespace on delimiters. + + :param dict it: The data structure to serialize + :return: JSON string, no whitespace between separators + """ return json.dumps(to_serialize, separators=(',', ':')) def download_menu(menu_params): + """Download the menu for a specific canteen. + + :param MenuParams menu_params: the target canteen + """ context = { 'record': 'pages_66', 'path': 'tt_content.list.20.ddfmensa_ddfmensajson' diff --git a/stw_potsdam/config.py b/stw_potsdam/config.py index 415c215..6503281 100644 --- a/stw_potsdam/config.py +++ b/stw_potsdam/config.py @@ -3,8 +3,12 @@ import ConfigParser import io import os + +from collections import namedtuple from functools import partial -from stw_potsdam.canteen import Canteen + +Canteen = namedtuple('Canteen', + ('key', 'name', 'street', 'city', 'id', 'chash')) def _get_config(filename): @@ -26,5 +30,9 @@ def _parse_canteen(config, canteen_name): def read_canteen_config(): + """Read the configured canteens from file. + + :return: dictionary which maps from canteen short name to :class:`Canteen`. + """ config = _get_config('canteens.ini') return {name: _parse_canteen(config, name) for name in config.sections()} diff --git a/stw_potsdam/feed.py b/stw_potsdam/feed.py index cb21e6c..656d6a9 100644 --- a/stw_potsdam/feed.py +++ b/stw_potsdam/feed.py @@ -51,6 +51,11 @@ def _process_day(builder, day): def render_menu(menu): + """Render the menu for a canteen into an OpenMensa XML feed. + + :param dict menu: the Python representation of the API JSON response + :return: the XML feed as string + """ builder = LazyBuilder() for day in _active_days(menu): @@ -60,6 +65,11 @@ def render_menu(menu): def render_meta(canteen, menu_feed_url): + """Render a OpenMensa XML meta feed for a given canteen. + + :param Canteen canteen: the canteen + :return: the XML meta feed as string + """ builder = LazyBuilder() builder.name = canteen.name