Cleanup: remove tiny 'canteen' module, document main entry points

This commit is contained in:
Falco Duersch
2018-09-26 16:14:35 +02:00
committed by f4lco
parent 8edc5a0ced
commit 221d1ab964
4 changed files with 28 additions and 8 deletions
-6
View File
@@ -1,6 +0,0 @@
# -*- encoding: utf-8 -*-
from collections import namedtuple
Canteen = namedtuple('Canteen',
('key', 'name', 'street', 'city', 'id', 'chash'))
+9 -1
View File
@@ -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'
+9 -1
View File
@@ -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()}
+10
View File
@@ -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