From c9c7d389c45815e1b7abd7bea7dc5093a3630ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Tue, 10 Oct 2017 11:45:50 +0200 Subject: Moved stuff to a module folder, preparing for setuptools --- mensa/logic.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 mensa/logic.py (limited to 'mensa/logic.py') diff --git a/mensa/logic.py b/mensa/logic.py new file mode 100755 index 0000000..b0165f0 --- /dev/null +++ b/mensa/logic.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 + +from mensa import base +import urllib.error +import os +from yapsy.PluginManager import PluginManager + + +def init_foodsources(): + backends = PluginManager() + backends.setPluginPlaces([os.path.join(os.path.dirname(os.path.realpath(__file__)),"backends")]) + backends.collectPlugins() + for pluginInfo in backends.getAllPlugins(): + backends.activatePluginByName(pluginInfo.name) + pluginInfo.plugin_object.register_restaurants() + +def init_renderers(): + frontends = PluginManager() + frontends.setPluginPlaces([os.path.join(os.path.dirname(os.path.realpath(__file__)),"frontends")]) + frontends.collectPlugins() + for pluginInfo in frontends.getAllPlugins(): + frontends.activatePluginByName(pluginInfo.name) + pluginInfo.plugin_object.register_renderer() + + +def get_food(restlist=False, options={}) : + foodl = [] + for k,i in base.foodsources.items() : + if restlist and not i.name in restlist : + continue + try : + food = i.get_food(ignore_nudelauswahl=True) + foodl.append((i, food)) + # print("*"*20+i.human_name+"*"*20+"\n"+base.formt(food)) + except base.NoMenuError: + print(i.human_name + ": No menu found. This could be due to a holiday or due to an error in the script.") + except urllib.error.HTTPError as e : + print(i.human_name + ": Fetching menu failed: %s" % str(e)) + return foodl + +def render(to_render, rendlist=False, options={}) : + for k,i in base.renderers.items() : + if rendlist and not i.name in rendlist : + continue + i.render(to_render) -- cgit v1.2.3