Cleanup: remove tiny 'canteen' module, document main entry points
This commit is contained in:
@@ -1,6 +0,0 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
|
||||||
|
|
||||||
from collections import namedtuple
|
|
||||||
|
|
||||||
Canteen = namedtuple('Canteen',
|
|
||||||
('key', 'name', 'street', 'city', 'id', 'chash'))
|
|
||||||
@@ -11,11 +11,19 @@ URL = 'https://www.studentenwerk-potsdam.de' + \
|
|||||||
|
|
||||||
|
|
||||||
def _param_json(to_serialize):
|
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=(',', ':'))
|
return json.dumps(to_serialize, separators=(',', ':'))
|
||||||
|
|
||||||
|
|
||||||
def download_menu(menu_params):
|
def download_menu(menu_params):
|
||||||
|
"""Download the menu for a specific canteen.
|
||||||
|
|
||||||
|
:param MenuParams menu_params: the target canteen
|
||||||
|
"""
|
||||||
context = {
|
context = {
|
||||||
'record': 'pages_66',
|
'record': 'pages_66',
|
||||||
'path': 'tt_content.list.20.ddfmensa_ddfmensajson'
|
'path': 'tt_content.list.20.ddfmensa_ddfmensajson'
|
||||||
|
|||||||
@@ -3,8 +3,12 @@
|
|||||||
import ConfigParser
|
import ConfigParser
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from stw_potsdam.canteen import Canteen
|
|
||||||
|
Canteen = namedtuple('Canteen',
|
||||||
|
('key', 'name', 'street', 'city', 'id', 'chash'))
|
||||||
|
|
||||||
|
|
||||||
def _get_config(filename):
|
def _get_config(filename):
|
||||||
@@ -26,5 +30,9 @@ def _parse_canteen(config, canteen_name):
|
|||||||
|
|
||||||
|
|
||||||
def read_canteen_config():
|
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')
|
config = _get_config('canteens.ini')
|
||||||
return {name: _parse_canteen(config, name) for name in config.sections()}
|
return {name: _parse_canteen(config, name) for name in config.sections()}
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ def _process_day(builder, day):
|
|||||||
|
|
||||||
|
|
||||||
def render_menu(menu):
|
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()
|
builder = LazyBuilder()
|
||||||
|
|
||||||
for day in _active_days(menu):
|
for day in _active_days(menu):
|
||||||
@@ -60,6 +65,11 @@ def render_menu(menu):
|
|||||||
|
|
||||||
|
|
||||||
def render_meta(canteen, menu_feed_url):
|
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 = LazyBuilder()
|
||||||
|
|
||||||
builder.name = canteen.name
|
builder.name = canteen.name
|
||||||
|
|||||||
Reference in New Issue
Block a user