-
Notifications
You must be signed in to change notification settings - Fork 0
/
_menu.py
237 lines (205 loc) · 10.1 KB
/
_menu.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
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
import asyncio
import datetime
import discord
import pytz
from bidict import bidict
from discord import Webhook
import aiohttp
import _reference
INPUTS = {
"today": "Today's Menu",
"chef": "Chef's Table Dinner",
"chefbr": "Chef's Table Breakfast",
"pizza": "Pizza (Lunch / Dinner)",
"pasta": "Pasta (Lunch / Dinner)",
"grill": "The Grill (Lunch / Dinner)",
"grillbr": "The Grill (Breakfast)",
"nourish": "Nourish (Lunch)",
"full": "Full Menu"
}
positions: bidict[str, int] = bidict({
"Chef's Table Breakfast (8am-1030am)": 0,
"Chef's Table (5pm-930pm)": 1,
"Pizza (1130am-3pm, 5pm-930pm)": 2,
"Pasta (1130am-3pm, 5pm-930pm)": 3,
"Grill House Breakfast (7-1030am)": 4,
"Grill House (1130am-3pm, 5pm-930pm)": 5,
"Nourish (1130am-3pm)": 6
})
def get_today():
pst = pytz.timezone('US/Pacific')
return datetime.datetime.now(tz=pst)
last_day = get_today()
current_day = get_today()
async def day_check():
global last_day, current_day
while True:
current_day = get_today()
if current_day.day != last_day.day:
last_day = current_day
await send_daily_menu()
await asyncio.sleep(3600) # 1hr
def between_callback(loop):
loop.create_task(day_check())
async def send_daily_menu():
async with aiohttp.ClientSession() as session:
with open(".webhook.txt", "r") as f:
content = f.readlines()
webhook = Webhook.from_url(content[0], session=session)
embed = await _reference.get_message(None, None)
await webhook.send(embed=embed, username="UBCO 2025 Webhook",
avatar_url="https://cdn.discordapp.com/avatars/897829450857726003/c58e8db16963e74566943d817dd79e9a.webp?size=160")
def contains_lower(s):
for character in s:
if character.islower():
return True
return False
def is_int(s):
try:
int(s)
return True
except ValueError:
return False
def end_of_month(dt):
todays_month = dt.month
tomorrows_month = (dt + datetime.timedelta(days=1)).month
return True if tomorrows_month != todays_month else False
def generate_menu(do: bool, month_num: str):
if not do:
return
with open("menu.txt", 'r') as menu_txt:
menu_json = _reference.get_file("menu")
lines = menu_txt.readlines()
if month_num not in menu_json.keys():
menu_json[month_num] = {}
current_day_str = "0"
current_stand = ""
for line in lines:
line = line.strip()
if is_int(line):
current_day_str = line
if current_day_str not in menu_json[month_num].keys():
menu_json[month_num][current_day_str] = {}
continue
if contains_lower(line):
current_stand = line
if current_stand not in menu_json[month_num][current_day_str].keys():
menu_json[month_num][current_day_str][current_stand] = []
continue
menu_json[month_num][current_day_str][current_stand].append(line)
_reference.save_file("menu", menu_json)
def generate_menu_json():
menu_json = _reference.get_file("menu")
today = get_today()
monday = today - datetime.timedelta(days=today.weekday())
sunday = monday + datetime.timedelta(days=6)
current_month_json = menu_json[str(monday.month)]
next_month_json: dict | None = None
if sunday.month > monday.month:
next_month_json = menu_json[str(sunday.month)]
json_content = {}
if next_month_json is None:
for day in range(monday.day, sunday.day + 1):
day_json = current_month_json[str(day)]
day -= monday.day
for stand in day_json.keys():
if str(positions[stand]) not in json_content.keys():
json_content[str(positions[stand])] = {}
if str(day) not in json_content[str(positions[stand])].keys():
json_content[str(positions[stand])][str(day)] = []
for dish in day_json[stand]:
json_content[str(positions[stand])][str(day)].append(dish.lower().capitalize())
else:
next_month = False
stored_offset = 6
for day_offset in range(0, 7):
day = monday.day + day_offset
if next_month:
day = sunday.day - stored_offset
day_json = next_month_json[str(day)]
else:
day_json = current_month_json[str(day)]
day = day_offset
for stand in day_json.keys():
if str(positions[stand]) not in json_content.keys():
json_content[str(positions[stand])] = {}
if str(day) not in json_content[str(positions[stand])].keys():
json_content[str(positions[stand])][str(day)] = []
for dish in day_json[stand]:
json_content[str(positions[stand])][str(day)].append(dish.lower().capitalize())
if not next_month:
next_month = end_of_month(monday + datetime.timedelta(days=day_offset))
stored_offset -= 1
return json_content
def get_display(menu, selected_input) -> tuple[discord.Embed, discord.Embed]:
today = get_today()
choices = {
"chefbr": 0,
"chef": 1,
"pizza": 2,
"pasta": 3,
"grillbr": 4,
"grill": 5,
"nourish": 6,
"today": 7,
"full": 8
}
choice = choices[selected_input]
display, dm_embed = discord.Embed(title=INPUTS[selected_input],
color=discord.colour.Colour.blue()), None
if choice <= 5:
display.add_field(name="Monday", value="- " + "\n- ".join(menu[str(choice)]['0']), inline=True)
display.add_field(name="Tuesday", value="- " + "\n- ".join(menu[str(choice)]['1']), inline=True)
display.add_field(name="Wednesday", value="- " + "\n- ".join(menu[str(choice)]['2']), inline=True)
display.add_field(name="Thursday", value="- " + "\n- ".join(menu[str(choice)]['3']), inline=True)
display.add_field(name="Friday", value="- " + "\n- ".join(menu[str(choice)]['4']), inline=True)
display.add_field(name="Saturday", value="- " + "\n- ".join(menu[str(choice)]['5']), inline=True)
display.add_field(name="Sunday", value="- " + "\n- ".join(menu[str(choice)]['6']), inline=True)
elif choice == 6:
display.add_field(name="Monday", value="- " + "\n- ".join(menu[str(choice)]['0']), inline=True)
display.add_field(name="Tuesday", value="- " + "\n- ".join(menu[str(choice)]['1']), inline=True)
display.add_field(name="Wednesday", value="- " + "\n- ".join(menu[str(choice)]['2']), inline=True)
display.add_field(name="Thursday", value="- " + "\n- ".join(menu[str(choice)]['3']), inline=True)
display.add_field(name="Friday", value="- " + "\n- ".join(menu[str(choice)]['4']), inline=True)
display.add_field(name="Weekends", value="Not Open on Weekends", inline=True)
elif choice == 7:
display.add_field(name=INPUTS["chefbr"], value="- " + "\n- ".join(menu['0'][str(today.weekday())]))
display.add_field(name=INPUTS["chef"], value="- " + "\n- ".join(menu['1'][str(today.weekday())]))
display.add_field(name=INPUTS["pizza"], value="- " + "\n- ".join(menu['2'][str(today.weekday())]))
display.add_field(name=INPUTS["pasta"], value="- " + "\n- ".join(menu['3'][str(today.weekday())]))
display.add_field(name=INPUTS["grillbr"], value="- " + "\n- ".join(menu['4'][str(today.weekday())]))
display.add_field(name=INPUTS["grill"], value="- " + "\n- ".join(menu['5'][str(today.weekday())]))
display.add_field(name=INPUTS["nourish"], value="- " + "\n- ".join(menu['6'][str(today.weekday())]
if today.weekday() < 5 else ["Not Open Today"]))
elif choice == 8:
display.description = "Full Menu sent in direct messages"
dm_embed = discord.Embed(title=INPUTS[selected_input],
color=discord.colour.Colour.blue())
format_menus = []
for i in range(0, 6):
format_menus.append("**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}"
.format("Monday", "\n- ".join(menu[str(i)]['0']),
"Tuesday", "\n- ".join(menu[str(i)]['1']),
"Wednesday", "\n- ".join(menu[str(i)]['2']),
"Thursday", "\n- ".join(menu[str(i)]['3']),
"Friday", "\n- ".join(menu[str(i)]['4']),
"Saturday", "\n- ".join(menu[str(i)]['5']),
"Sunday", "\n- ".join(menu[str(i)]['6'])))
nourish = "n**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}\n**{}**\n- {}" \
.format("Monday", "\n- ".join(menu['6']['0']),
"Tuesday", "\n- ".join(menu['6']['1']),
"Wednesday", "\n- ".join(menu['6']['2']),
"Thursday", "\n- ".join(menu['6']['3']),
"Friday", "\n- ".join(menu['6']['4']),
"Saturday", "\n- ".join(["Not Open Today"]),
"Sunday", "\n- ".join(["Not Open Today"]))
dm_embed.add_field(name="> **Chef's Table Breakfast**", value=format_menus[0], inline=False)
dm_embed.add_field(name="> **Chef's Table Dinner**", value=format_menus[1], inline=False)
dm_embed.add_field(name="> **Pizza (Lunch / Dinner)**", value=format_menus[2], inline=False)
dm_embed.add_field(name="> **Pasta (Lunch / Dinner)**", value=format_menus[3], inline=False)
dm_embed.add_field(name="> **The Grill (Breakfast)**", value=format_menus[4], inline=False)
dm_embed.add_field(name="> **The Grill (Lunch / Dinner)**", value=format_menus[5], inline=False)
dm_embed.add_field(name="> **Nourish (Lunch)**", value=nourish, inline=False)
return display, dm_embed
async def get_weekly_menu() -> dict:
return generate_menu_json()