From 6000a3a6e5acf073a224e74be590407616eeeffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Tue, 6 Mar 2018 11:05:23 +0100 Subject: --no-parallel option to fix studentenwerk behaviour, option to show only student prices to avoid clutter --- bin/mensa | 12 ++++++++---- mensa/base.py | 3 +++ mensa/frontends/html.py | 6 +++++- mensa/frontends/plain-text.py | 6 +++++- mensa/logic.py | 5 +++-- setup.py | 2 +- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/bin/mensa b/bin/mensa index 0ccad0c..6e603cd 100755 --- a/bin/mensa +++ b/bin/mensa @@ -15,18 +15,22 @@ parser.add_argument('-g', '--vegetarian', dest='vegetarian', action='store_true help='show only vegetarian meals') parser.add_argument('-G', '--vegan', dest='vegan', action='store_true', help='show only vegan meals') +parser.add_argument('-s', '--student-prices', dest='student', action='store_true', default=False, + help='show only student prices') + +parser.add_argument('--no-parallel', dest="no_parallel", action="store_true", default=False, help="Do not parallelize fetching, might help with rate-limited websites") args = parser.parse_args() ## Load backends logic.init_foodsources() -## Load frontends (not yet implemented) +## Load frontends logic.init_renderers() veggie = 0 form = ["plain-text"] if args.form : form = args.form - + if args.vegetarian : veggie = 1 @@ -43,5 +47,5 @@ restlist = None if args.rest : restlist = args.rest -foodl = logic.get_food(restlist) -logic.render(foodl, form, only_veggie=veggie) +foodl = logic.get_food(restlist, no_parallel=args.no_parallel) +logic.render(foodl, form, only_veggie=veggie, only_student_prices=args.student) diff --git a/mensa/base.py b/mensa/base.py index fa7346a..a6e8cfa 100644 --- a/mensa/base.py +++ b/mensa/base.py @@ -57,3 +57,6 @@ def register_restaurant(restaurant): def register_renderer(renderer) : global renderers renderers[renderer.name] = renderer + +def only_student_prices(price): + return price.split("/")[0] diff --git a/mensa/frontends/html.py b/mensa/frontends/html.py index 8ffec37..8a5618f 100644 --- a/mensa/frontends/html.py +++ b/mensa/frontends/html.py @@ -14,6 +14,10 @@ class HTMLRenderer(IPlugin) : r = r+"

"+esc(restaurant.human_name)+"

"+"\n"#+base.formt(food) 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 : @@ -22,7 +26,7 @@ class HTMLRenderer(IPlugin) : cat.append(i.category) if not i.category == None : r=r+ "

"+esc(i.category)+"

" diff --git a/mensa/frontends/plain-text.py b/mensa/frontends/plain-text.py index 7a31371..9147133 100644 --- a/mensa/frontends/plain-text.py +++ b/mensa/frontends/plain-text.py @@ -12,13 +12,17 @@ class TextRenderer(IPlugin) : r = r+"*"*20+restaurant.human_name+"*"*20+"\n"#+base.formt(food) 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"+ i.price.ljust(20) + vegkeys[i.veggie]+"\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" print(r) diff --git a/mensa/logic.py b/mensa/logic.py index 75b2465..cae2421 100755 --- a/mensa/logic.py +++ b/mensa/logic.py @@ -28,9 +28,10 @@ def init_renderers(): pluginInfo.plugin_object.register_renderer() -def get_food(restlist=False, **options) : +def get_food(restlist=False, no_parallel=False,**options) : foodl = [] - if parallel : + + if parallel and not no_parallel: r = [] for k,i in base.foodsources.items() : if restlist and not i.name in restlist : diff --git a/setup.py b/setup.py index 2ec44af..40d69a9 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ def read(fname): setup( name = "mensa", - version = "0.3", + version = "0.3.1", author = "Gabriel PĂ©rez-Cerezo", author_email = "gabriel@gpcf.eu", description = ("A program that fetches menus from various restaurants. Pre-installed by default are various cafeterias around TU Berlin."), -- cgit v1.2.3