diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2018-09-03 09:18:28 +0200 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2018-09-03 09:18:28 +0200 |
commit | 3d4cb8555196a08347e373b6e542f80159155261 (patch) | |
tree | 9abb893a39da87f927d3180f27e787be619f3fed /mensa/frontends/plain-text.py | |
parent | 0e757e1d3822a0adeeb086fbf3e56c20cb1bdb40 (diff) | |
download | mensa-3d4cb8555196a08347e373b6e542f80159155261.tar.gz mensa-3d4cb8555196a08347e373b6e542f80159155261.tar.bz2 mensa-3d4cb8555196a08347e373b6e542f80159155261.zip |
Cleanup, bump version to 0.4
This version breaks backend compatibility with 0.3.x; it turns the old
list-based format into an OrderedDict-based format, sorted by
category. This makes the renderers cleaner and easier to write.
Diffstat (limited to 'mensa/frontends/plain-text.py')
-rw-r--r-- | mensa/frontends/plain-text.py | 32 |
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) : |