aboutsummaryrefslogtreecommitdiff
path: root/base.py
blob: df7bd4ace95d51d42516a3f8e72fb8669cf886c6 (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
52
# Common classes and methods.

class Food :
    def __init__(self,name, price="", category="Essen", veggie=False, desc=None, ingredients={}) :
        self.name = name
        self.price = price
        self.category = category
        self.veggie = veggie
        self.desc=desc
        self.ingredients=ingredients

class NoMenuError(Exception) :
    """ gets raised if there's no menu"""

class Frontend(object) :
    def __init__(self, name, human_name, description="", optional_args=[]) :
        self.name = name
        self.human_name = human_name
        self.description = description
        self.optional_args = []
        
def formt (food) :
    cat = []
    vegkeys = [ "", "Vegetarian", "Vegan" ]
    r = ""
    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"
    return r

foodsources = {}

class Restaurant(object):
    def __init__(self, name, human_name, module, optional_args=[], obligatory_args=()):
        self.name = name
        self.human_name = human_name
        self.module = module
        self.optional_args = optional_args
        self.obligatory_args = obligatory_args

    def get_food(self,**opt_args) :
        return self.module.get_food_items(*self.obligatory_args, **opt_args)

def register_restaurant(restaurant):
    global foodsources
    foodsources[restaurant.name] = (restaurant)