aboutsummaryrefslogtreecommitdiff
path: root/mensa/frontends/plain-text.py
diff options
context:
space:
mode:
Diffstat (limited to 'mensa/frontends/plain-text.py')
-rw-r--r--mensa/frontends/plain-text.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/mensa/frontends/plain-text.py b/mensa/frontends/plain-text.py
index 36b2a34..8f3f736 100644
--- a/mensa/frontends/plain-text.py
+++ b/mensa/frontends/plain-text.py
@@ -1,33 +1,29 @@
from mensa import base
from yapsy.IPlugin import IPlugin
class TextRenderer(IPlugin) :
+ def render_line(self, item) :
+ vegkeys = [ "", "Vegetarian", "Vegan" ]
+ if self.options.get("only_veggie",0) > item.veggie :
+ return ""
+ desc = ""
+ if item.desc :
+ desc = "\t "+item.desc+"\n"
+ return "\t" + item.name.ljust(80) + "\t"+ item.price.ljust(20) + vegkeys[item.veggie]+"\n"+desc
+
def render (self, foods, **options) :
+ self.options = options
## Expects list of tuples with (Restaurant, Foodlist)
r = ""
- vegkeys = [ "", "Vegetarian", "Vegan" ]
for restaurant, food in foods :
cat = []
if not food :
continue
- r = r+"*"*20+restaurant.human_name+"*"*20+"\n"#+base.formt(food)
- if "pos" in options and restaurant.pos and "dist" in options :
+ r = r+"*"*20+restaurant.human_name+"*"*20+"\n"
+ if "pos" in options and restaurant.pos and options.get("dist") :
## display distance to restaurant
r=r+"Distance: %.2f km\n" % base.dist(options["pos"], restaurant.pos)
- food.sort(key=lambda foo: foo.category)
- for i in food:
- if options["only_student_prices"] :
- price = base.only_student_prices(i.price)
- else:
- price = i.price
- if options["only_veggie"] and options["only_veggie"] > i.veggie :
- continue
- 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"+ price.ljust(20) + vegkeys[i.veggie]+"\n"
- if i.desc :
- r = r+"\t "+i.desc+"\n"
+
+ r= r + "".join([category+"\n" + "".join([self.render_line(i) for i in items]) for category,items in food.items()])
print(r)
def register_renderer(self) :