aboutsummaryrefslogtreecommitdiff
path: root/menu/menu_weekly.py
blob: c2984e5544da2e490d2c4892b8f9a79fef1068c7 (plain) (blame)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import re
import string
import PyPDF2 as pdf
import datetime


def split_string_en(string):
    pattern = r"[\u3000-\u303f\u4e00-\u9fff,)]+"
    en_substrings = filter(None, re.split(pattern, string))
    return list(en_substrings)


def split_string_zh(string):
    pattern = r'''[^\u3000-\u303f\u4e00-\u9fff ,),/&
]+'''
    zh_substrings = filter(None, re.split(pattern, string))
    return list(zh_substrings)


def split_list(lst, method):
    length = len(lst)
    if type(method) == type(1):
        method_cleaned = [method] * (length // method)
        if length % method:
            method_cleaned.append(length % method)
    else:
        method_cleaned = []
        method_sum = 0
        for i in method:
            if method_sum + i < length:
                method_cleaned.append(i)
                method_sum += i
            else:
                method_cleaned.append(length - method_sum)
                method_sum = length
                break
        if method_sum < length:
            method_cleaned.append(length - method_sum)
    result = []
    iterator = 0
    for i in method_cleaned:
        result.append([])
        for j in range(iterator, iterator + i):
            result[-1].append(lst[j])
        iterator += i
    return result


datetime_time = datetime.date.today() + datetime.timedelta(days=1)
formatted_time = datetime_time.strftime("%Y-%m-%d")

f = open(formatted_time + ".pdf", "rb")
r = pdf.PdfReader(f)
days = ["Mon", "Tue", "Wed", "Thu", "Fri"]

# Uncertainties
breakfast_info = [
    [1, 1, 1, 1, 1], # Header
    [1, 1, 1, 1, 1], # Taste of Asia
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1], # Eat Global
    [0, 1, 0, 1, 0],
    [0, 1, 0, 1, 0],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [0, 1, 1, 1, 1], # Revolution
    [0, 1, 1, 1, 1],
    [1, 1, 1, 1, 1], # Piccola Italia
    [1, 1, 1, 1, 1],
    [0, 1, 1, 1, 1],
    [0, 1, 1, 1, 1],
    [1, 1, 1, 1, 1], # Fruit / Drink
]
lunch_info = [
    [1, 1, 1, 1, 1], # Header
    [1, 1, 1, 1, 1], # Taste of Asia
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 0], # Eat Global
    [1, 1, 1, 1, 0],
    [1, 1, 1, 1, 0],
    [1, 1, 1, 1, 0],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1], # Revolution
    [1, 1, 1, 1, 1], # Piccola Italia
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1], # Vegetarian
    [1, 1, 1, 1, 1], # Daily Soup
    [1, 1, 1, 1, 1], # Dessert / Fruit / Drink
]
dinner_info = [
    [1, 1, 1, 1, 1], # Header
    [1, 1, 1, 1, 1], # Taste of Asia
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1], # Eat Global
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 0], # Revolution
    [1, 1, 1, 1, 0], # Piccola Italia
    [1, 1, 1, 1, 0], # Vegetarian
    [1, 1, 1, 1, 1], # Daily Soup
    [1, 1, 1, 1, 1], # Dessert / Fruit / Drink
]
breakfast_include = [0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
lunch_include = [0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0]
dinner_include = [0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0]



breakfast_en = split_list(
    list(
        filter(
            lambda x: x != "",
            map(
                lambda x: x.strip().strip(string.punctuation).replace("\n", " "),
                split_string_en(
                    r.pages[0]
                    .extract_text()
                    .replace("Orange , \nButter", "Orange, Butter)")
                    .replace("(", "")
                ),
            ),
        )
    ),
    list(map(sum, breakfast_info)),
)
lunch_en = split_list(
    list(
        filter(
            lambda x: x != "",
            map(
                lambda x: x.strip().strip(string.punctuation).replace("\n", " "),
                split_string_en(r.pages[1].extract_text().replace("(", "").replace(",", "")),
            ),
        )
    ),
    list(map(sum, lunch_info)),
)
dinner_en = split_list(
    list(
        filter(
            lambda x: x != "",
            map(
                lambda x: x.strip().strip(string.punctuation).replace("\n", " "),
                split_string_en(r.pages[2].extract_text().replace("(", "")),
            ),
        )
    ),
    list(map(sum, dinner_info)),
)
breakfast_zh = split_list(
    list(
        filter(
            lambda x: x != "",
            map(
                lambda x: x.strip().strip(string.punctuation).replace("\n", " "),
                split_string_zh(
                    r.pages[0]
                    .extract_text()
                    .replace("Orange , \nButter", "Orange, Butter)")
                    .replace("(", "")
                ),
            ),
        )
    ),
    list(map(sum, breakfast_info)),
)
lunch_zh = split_list(
    list(
        filter(
            lambda x: x != "",
            map(
                lambda x: x.strip().strip(string.punctuation).replace("\n", " "),
                split_string_zh(r.pages[1].extract_text().replace("(", "").replace(",", "")),
            ),
        )
    ),
    list(map(sum, lunch_info)),
)
dinner_zh = split_list(
    list(
        filter(
            lambda x: x != "",
            map(
                lambda x: x.strip().strip(string.punctuation).replace("\n", " "),
                split_string_zh(r.pages[2].extract_text().replace("(", "")),
            ),
        )
    ),
    list(map(sum, dinner_info)),
)


def output():

    html_str = ""
    html_str += """<table>
\t<caption>Breakfast 早餐</caption>
\t<colgroup>
\t\t<col style="width: 5%">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%; border-left: 2px solid rgb(180, 180, 180);">
\t</colgroup>
\t<thead>
\t\t<tr>
\t\t\t<th scope="col">Day</th>
\t\t\t<th scope="colgroup" colspan=3>Taste of Asia</th>
\t\t\t<th scope="colgroup" colspan=3>Eat Global</th>
\t\t\t<th scope="col">Revolution</th>
\t\t\t<th scope="col">Morning Snack</th>
\t\t</tr>
\t</thead>
\t<tbody>\n"""
    for day in range(5):
        if day == 0: 
            html_str += f'\t\t<tr class="today">\n\t\t\t<th scope="row">{days[day]}</th>\n'
        else: 
            html_str += f'\t\t<tr class="not-today">\n\t\t\t<th scope="row">{days[day]}</th>\n'
        for i in range(len(breakfast_en)):
            if breakfast_include[i]:
                if breakfast_info[i][day]:
                    index = sum(breakfast_info[i][:day])
                    html_str += f"\t\t\t<td>{breakfast_en[i][index]}<br>{breakfast_zh[i][index]}</td>\n"
                else:
                    html_str += "\t\t\t<td></td>\n"
        html_str += "\t\t\t<td></td>\n\t\t</tr>\n"
    html_str += """\t\t<tr class="expand">
\t\t\t<th>+</th>
\t\t</tr>
\t</tbody>
</table>
"""

    html_str += """
<table>
\t<caption>Lunch 午餐</caption>
\t<colgroup>
\t\t<col style="width: 5%">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%; border-left: 2px solid rgb(180, 180, 180);">
\t</colgroup>
\t<thead>
\t\t<tr>
\t\t\t<th scope="col">Day</th>
\t\t\t<th scope="colgroup" colspan=2>Taste of Asia</th>
\t\t\t<th scope="colgroup" colspan=2>Eat Global</th>
\t\t\t<th scope="col">Revolution</th>
\t\t\t<th scope="col">Piccola Italia</th>
\t\t\t<th scope="col">Vegetarian</th>
\t\t\t<th scope="col">Afternoon Snack</th>
\t\t</tr>
\t</thead>
\t<tbody>\n"""
    for day in range(5):
        if day == 0: 
            html_str += f'\t\t<tr class="today">\n\t\t\t<th scope="row">{days[day]}</th>\n'
        else: 
            html_str += f'\t\t<tr class="not-today">\n\t\t\t<th scope="row">{days[day]}</th>\n'
        for i in range(len(lunch_en)):
            if lunch_include[i]:
                if lunch_info[i][day]:
                    index = sum(lunch_info[i][:day])
                    html_str += f"\t\t\t<td>{lunch_en[i][index]}<br>{lunch_zh[i][index]}</td>\n"
                else:
                    html_str += "\t\t\t<td></td>\n"
        html_str += "\t\t\t<td></td>\n\t\t</tr>\n"
    html_str += """\t\t<tr class="expand">
\t\t\t<th>+</th>
\t\t</tr>
\t</tbody>
</table>
"""

    html_str += """
<table>
\t<caption>Dinner 晚餐</caption>
\t<colgroup>
\t\t<col style="width: 5%">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%;">
\t\t<col style="width: 11.875%; border-left: 2px solid rgb(180, 180, 180);">
\t</colgroup>
\t<thead>
\t\t<tr>
\t\t\t<th scope="col">Day</th>
\t\t\t<th scope="colgroup" colspan=2>Taste of Asia</th>
\t\t\t<th scope="colgroup" colspan=2>Eat Global</th>
\t\t\t<th scope="col">Revolution</th>
\t\t\t<th scope="col">Piccola Italia</th>
\t\t\t<th scope="col">Vegetarian</th>
\t\t\t<th scope="col">Evening Snack</th>
\t\t</tr>
\t</thead>
\t<tbody>\n"""   
    evening_snacks = ["Fruit & Fruit Yogurt<br>水果 & 果味酸奶", "Fruit & Yogurt<br>水果 & 酸奶", "Fruit & Chocolate Soy Milk<br>水果 & 巧克力豆奶", "Fruit & Yogurt<br>水果 & 酸奶"]

    for day in range(4):
        if day == 0: 
            html_str += f'\t\t<tr class="today">\n\t\t\t<th scope="row">{days[day]}</th>\n'
        else: 
            html_str += f'\t\t<tr class="not-today">\n\t\t\t<th scope="row">{days[day]}</th>\n'
        for i in range(len(dinner_en)):
            if dinner_include[i]:
                if dinner_info[i][day]:
                    index = sum(dinner_info[i][:day])
                    html_str += f"\t\t\t<td>{dinner_en[i][index]}<br>{dinner_zh[i][index]}</td>\n"
                else:
                    html_str += "\t\t\t<td></td>\n"
        html_str += f"\t\t\t<td>{evening_snacks[day]}</td>\n\t\t</tr>\n"
    html_str += """\t\t<tr class="expand">
\t\t\t<th>+</th>
\t\t</tr>
\t</tbody>
</table>
"""

    with open("latest_raw.html", "w") as file:
        file.write(html_str)
        file.close()


output()