aboutsummaryrefslogtreecommitdiff
path: root/bin/mensa
blob: 6e603cd5a0c3c4b501efe1e9a270ebba9636f6ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3
import argparse

from mensa import logic
from mensa import base

parser = argparse.ArgumentParser(description='Fetch menus from various sources')
parser.add_argument('rest', nargs="*",
                    metavar='RESTAURANT',
                    help='Fetch menus from this restaurant')
parser.add_argument('-l', '--list-restaurants',  dest='list', action='store_true',
                    help='get list of restaurants')
parser.add_argument('-f', '--formatter', dest='form', action='store', nargs=1, help="formatter to use")
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
logic.init_renderers()
veggie = 0
form = ["plain-text"]
if args.form :
    form = args.form


if args.vegetarian :
    veggie = 1
if args.vegan :
    veggie = 2



if args.list :
    for k,i in base.foodsources.items():
        print(i.name, i.human_name)
    exit()
restlist = None
if args.rest :
    restlist = args.rest

foodl = logic.get_food(restlist, no_parallel=args.no_parallel)
logic.render(foodl, form, only_veggie=veggie, only_student_prices=args.student)