Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import os
- import requests
- from datetime import date, timedelta
- import re
- # link: https://discord.com/api/oauth2/authorize?client_id=943981035950051328&permissions=534723947584&scope=bot
- client = discord.Client()
- def search():
- full_menu = ""
- day = date.today()
- delta = timedelta(days=1)
- cheesecake_dates = []
- today = False
- for i in range(7):
- d_str = day.strftime("%m/%d/%y")
- full_menu += d_str+"\n"
- day += delta
- query = {'tid':'1', 'date':d_str}
- response = requests.get("https://umassdining.com/foodpro-menu-ajax", params=query)
- j = response.json()
- for key in j.keys():
- meal = j[key]
- if 'Desserts' in meal.keys():
- d = meal['Desserts']
- r = re.findall('data-dish-name=\"([^\"]*)\"', d)
- for dessert in r:
- if dessert.lower().find('cheesecake') > -1:
- if i == 0:
- today = True
- elif len(cheesecake_dates) == 0 or cheesecake_dates[len(cheesecake_dates)-1] != day.strftime('%A'):
- cheesecake_dates.append(day.strftime('%A'))
- full_menu += key.capitalize() + ': ' + ', '.join(r) + "\n"
- to_return = ''
- if(today):
- to_return += "There is cheescake today! :)\n"
- if len(cheesecake_dates) == 1:
- to_return +="There is also cheesecake on "+cheesecake_dates[0]+"!\n"
- elif len(cheesecake_dates) > 1:
- to_return +="There is also cheesecake on "+cheesecake_dates[0]+" and "+cheesecake_dates[1]+"!\n"
- elif len(cheesecake_dates) == 1:
- to_return +="There is no cheesecake today :(, but there is cheesecake on "+cheesecake_dates[0]+"!\n"
- elif len(cheesecake_dates) > 1:
- to_return +="There is no cheesecake today :(, but there is cheesecake on "+cheesecake_dates[0]+" and "+cheesecake_dates[1]+"!\n"
- else:
- to_return += "There is no cheesecake this week :(\n"
- to_return += "\nHere's the full menu:\n"
- to_return += '```\n'
- to_return += full_menu
- to_return += '\n```'
- return to_return
- @client.event
- async def on_ready():
- print("Loaded")
- @client.event
- async def on_message(message):
- if message.author == client.user:
- return
- content = message.clean_content.lower()
- if content.find('cheesecakebot') > -1 or content.find('cheescakebot') > -1 or content.find('dessert') > -1 or content.find('menu') > -1:
- await message.channel.send(search())
- elif len(re.findall("c[\W]*h[\W]*e[\W]*e[\W]*s[\W]*e?[\W]*c[\W]*a[\W]*k[\W]*e", content)) > 0:
- await message.channel.send('Cheesecake!')
- client.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment