Skip to content

Commit

Permalink
Enable "tomorrow's menu" option
Browse files Browse the repository at this point in the history
 * users can query "What is in breakfast tomorrow" and get a response
 * feature request stemmed from observing user message logs
  • Loading branch information
rhl-bthr committed Oct 29, 2019
1 parent acc0a7e commit f4f2516
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/query_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def sort_query(msg_text, sender_id):

for meal in ["lunch", "dinner", "breakfast"]:
if meal in msg_list:
message_pack = get_text(get_meal(meal))
if 'tomorrow' in msg_list:
message_pack = get_text(get_meal(meal,tomorrow=True))
else:
message_pack = get_text(get_meal(meal))

if not message_pack:
message_pack = sort(msg_list)
Expand Down Expand Up @@ -122,7 +125,6 @@ def get_name(sender_id):
else:
return ''


def clean_text(text):
text = text.lower()
text = text.replace("'s", '')
Expand Down Expand Up @@ -156,12 +158,15 @@ def say_sorry():
return get_text(random.choice(sorry_msgs))


def get_meal(mealtype):
def get_meal(mealtype,tomorrow=False):
""" Get today's meal. mealtype: breakfast / lunch / dinner. """
now = datetime.datetime.now(
pytz.timezone(
'Asia/Kolkata')).date(
).strftime(
)
if tomorrow:
now += datetime.timedelta(days=1)
now = now.strftime(
'%d-%m-%Y')

if now != MESS['date']:
Expand All @@ -172,9 +177,14 @@ def get_meal(mealtype):
return "<Sorry, Menu will be updated by tonight>"

MESS['date'] = now
MESS["lunch"] = "Today's lunch:\n" + "\n".join(today["lunch"])
MESS["breakfast"] = "Today's breakfast:\n" + \

prefix = 'today\'s'
if tomorrow:
prefix = 'tomorrow\'s'

MESS["lunch"] = f"{prefix} lunch:\n" + "\n".join(today["lunch"])
MESS["breakfast"] = f"{prefix} breakfast:\n" + \
"\n".join(today["breakfast"])
MESS["dinner"] = "Today's dinner:\n" + "\n".join(today["dinner"])
MESS["dinner"] = f"{prefix} dinner:\n" + "\n".join(today["dinner"])

return MESS[mealtype]

0 comments on commit f4f2516

Please sign in to comment.