aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2017-10-04 16:03:29 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2017-10-04 16:03:29 +0200
commitaa70fb739bbcb4f7a5275fc6a8dac4b3b84579e6 (patch)
tree7765ef60ffaa4f96723e7cec32504005f622aee7
parent6672aad7101f3593fde1009c36d0dde92ebc6512 (diff)
downloadmensa-aa70fb739bbcb4f7a5275fc6a8dac4b3b84579e6.tar.gz
mensa-aa70fb739bbcb4f7a5275fc6a8dac4b3b84579e6.tar.bz2
mensa-aa70fb739bbcb4f7a5275fc6a8dac4b3b84579e6.zip
Added mechanism for various output formats
-rw-r--r--frontends/plain-text.py22
-rw-r--r--frontends/plain-text.yapsy-plugin3
-rwxr-xr-xrun.py21
3 files changed, 40 insertions, 6 deletions
diff --git a/frontends/plain-text.py b/frontends/plain-text.py
new file mode 100644
index 0000000..71cbf42
--- /dev/null
+++ b/frontends/plain-text.py
@@ -0,0 +1,22 @@
+import base
+from yapsy.IPlugin import IPlugin
+class TextRenderer(IPlugin) :
+ def render (self, foods, **options) :
+ ## Expects list of tuples with (Restaurant, Foodlist)
+ r = ""
+ vegkeys = [ "", "Vegetarian", "Vegan" ]
+ for restaurant, food in foods :
+ cat = []
+ r = r+"*"*20+restaurant.human_name+"*"*20+"\n"#+base.formt(food)
+ food.sort(key=lambda foo: foo.category)
+ for i in food:
+ if not i.category in cat :
+ cat.append(i.category)
+ if not i.category == None :
+ r=r+ i.category+"\n"
+ r=r+"\t" + i.name.ljust(80) + "\t"+ i.price.ljust(20) + vegkeys[i.veggie]+"\n"
+ if i.desc :
+ r = r+"\t "+i.desc+"\n"
+ print(r)
+
+
diff --git a/frontends/plain-text.yapsy-plugin b/frontends/plain-text.yapsy-plugin
new file mode 100644
index 0000000..103cdc4
--- /dev/null
+++ b/frontends/plain-text.yapsy-plugin
@@ -0,0 +1,3 @@
+[Core]
+Name = Plain Text Output
+Module = plain-text \ No newline at end of file
diff --git a/run.py b/run.py
index 3ce971f..a4248d5 100755
--- a/run.py
+++ b/run.py
@@ -1,6 +1,7 @@
#!/usr/bin/python3
import base
+import urllib.error
import argparse
@@ -21,14 +22,17 @@ backends = PluginManager()
backends.setPluginPlaces(["./backends"])
backends.collectPlugins()
## Load frontends (not yet implemented)
-# from yapsy.PluginManager import PluginManager
-# frontends = PluginManager()
-# frontends.setPluginPlaces(["./frontends"])
-# frontends.collectPlugins()
+from yapsy.PluginManager import PluginManager
+frontends = PluginManager()
+frontends.setPluginPlaces(["./frontends"])
+frontends.collectPlugins()
for pluginInfo in backends.getAllPlugins():
backends.activatePluginByName(pluginInfo.name)
pluginInfo.plugin_object.register_restaurants()
+for pluginInfo in frontends.getAllPlugins():
+ frontends.activatePluginByName(pluginInfo.name)
+
if args.list :
for k,i in base.foodsources.items():
@@ -37,14 +41,19 @@ if args.list :
restlist = None
if args.rest :
restlist = args.rest.split(",")
-
+to_render = []
for k,i in base.foodsources.items() :
if restlist and not i.name in restlist :
continue
try :
food = i.get_food(ignore_nudelauswahl=True)
- print("*"*20+i.human_name+"*"*20+"\n"+base.formt(food))
+ to_render.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))
+
+for i in frontends.getAllPlugins():
+ print(i.name)
+ i.plugin_object.render(to_render)