-
Notifications
You must be signed in to change notification settings - Fork 0
/
canteenday.py
66 lines (47 loc) · 1.75 KB
/
canteenday.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from datetime import datetime
from typing import Dict, List
import canteen_properties as props
from mensa_queue import Queue
def remove_suffix(string: str, suffix: str) -> str:
if string.endswith(suffix):
return string[:-len(suffix)]
else:
return string
class CanteenDay:
def __init__(self, canteen_key: str, data: dict, date: datetime) -> None:
self.date: datetime = date
self.canteen_key = canteen_key
self.queue_dict: Dict[str, Queue] = {}
self._canteen_closed = True
for q_key, q_name in props.QUEUE_NAMES[canteen_key].items():
if q_key in data.keys():
q = Queue(q_name, data[q_key])
self.queue_dict[q_key] = q
if not q.closed:
self._canteen_closed = False
def get_list(self) -> List[Queue]:
return list(self.queue_dict.values())
def get_name(self):
return props.CANTEEN_NAMES[self.canteen_key]
@staticmethod
def get_name_of(key):
return props.CANTEEN_NAMES[key]
@staticmethod
def get_canteen_names() -> List:
return list(props.CANTEEN_NAMES.values())
@staticmethod
def get_canteen_names_short() -> List:
return list(props.CANTEEN_NAMES_SHORT.values())
@staticmethod
def get_canteen_keys() -> List:
return list(props.CANTEEN_NAMES.keys())
def get_canteen_closed(self):
return self._canteen_closed
def __str__(self) -> str:
out = f'<{self.date.__str__()}: '
for q_key, value in self.queue_dict.items():
out += f'{value.name}: {[meal.__str__() for meal in self.queue_dict[q_key].meals]}, '
# remove ', ' suffix
out = remove_suffix(out, ', ')
out += '>'
return out