mirror of
https://github.com/EDeev/school_menu.git
synced 2026-06-18 22:21:04 +03:00
Add files via upload
This commit is contained in:
parent
ca400878f9
commit
d72363734e
4 changed files with 150 additions and 0 deletions
3
base.py
Normal file
3
base.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
TOKEN = "2080341451:AAFy8rRr6Bv4Es9qdyUiwLF3wny3278mk7o"
|
||||||
|
|
||||||
|
GROUP_ID = "-1001652004653"
|
||||||
99
bot.py
Normal file
99
bot.py
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
import logging
|
||||||
|
import base, pars
|
||||||
|
import asyncio
|
||||||
|
import datetime as dt
|
||||||
|
|
||||||
|
from aiogram import Bot, Dispatcher, executor, types
|
||||||
|
|
||||||
|
# log level
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
# bot init
|
||||||
|
bot = Bot(token=base.TOKEN)
|
||||||
|
dp = Dispatcher(bot)
|
||||||
|
|
||||||
|
|
||||||
|
# events
|
||||||
|
@dp.message_handler(commands="today")
|
||||||
|
async def today(message: types.Message):
|
||||||
|
food = pars.eating(0)
|
||||||
|
if food:
|
||||||
|
eat = f"<b>Питание за {'.'.join(reversed(str(dt.date.today()).split('-')))}</b>\n\n"
|
||||||
|
for j in food:
|
||||||
|
eat = eat + "<i><b>" + j + ":</b></i>\n"
|
||||||
|
for i in food[j]:
|
||||||
|
eat = eat + "<b>* " + i[0] + "</b> <i>[ " +\
|
||||||
|
str(int(eval(i[1][0]))) + " г. " + str(i[1][1]) + " ккал. ]</i>" + "\n"
|
||||||
|
eat = eat + "\n\n"
|
||||||
|
await message.answer(eat, types.ParseMode.HTML)
|
||||||
|
else:
|
||||||
|
await message.answer(f"<b>Ошибка при выводе данных</b>\n\nВероятнее всего, либо вы вызываете команду в "
|
||||||
|
f"воскресенье, либо же данные о меню отсутствуют", types.ParseMode.HTML)
|
||||||
|
|
||||||
|
|
||||||
|
@dp.message_handler(commands="tomorrow")
|
||||||
|
async def tomorrow(message: types.Message):
|
||||||
|
food = pars.eating(1)
|
||||||
|
if food:
|
||||||
|
eat = f"<b>Питание за {'.'.join(reversed(str(dt.date.today() + dt.timedelta(days=1)).split('-')))}</b>\n\n"
|
||||||
|
for j in food:
|
||||||
|
eat = eat + "<i><b>" + j + ":</b></i>\n"
|
||||||
|
for i in food[j]:
|
||||||
|
eat = eat + "<b>* " + i[0] + "</b> <i>[ " +\
|
||||||
|
str(int(eval(i[1][0]))) + " г. " + str(i[1][1]) + " ккал. ]</i>" + "\n"
|
||||||
|
eat = eat + "\n\n"
|
||||||
|
await message.answer(eat, types.ParseMode.HTML)
|
||||||
|
else:
|
||||||
|
await message.answer(f"<b>Ошибка при выводе данных</b>\n\nВероятнее всего, либо вы вызываете команду на "
|
||||||
|
f"воскресенье, либо же данные о меню отсутствуют", types.ParseMode.HTML)
|
||||||
|
|
||||||
|
|
||||||
|
@dp.message_handler(commands="eat")
|
||||||
|
async def vote(message: types.Message):
|
||||||
|
await bot.send_message(chat_id=base.GROUP_ID,
|
||||||
|
text=f'*{message.chat.title}* >> '
|
||||||
|
f'[{message.from_user.first_name}](tg://user?id={message.from_user.id})\n'
|
||||||
|
f'*Заказывет:* {" ".join(message.text.split()[1:])}',
|
||||||
|
parse_mode=types.ParseMode.MARKDOWN)
|
||||||
|
|
||||||
|
|
||||||
|
@dp.message_handler(commands="help")
|
||||||
|
async def help(message: types.Message):
|
||||||
|
await message.answer('*Инструкция использования:*\n\n'
|
||||||
|
'*/eat {завтрак / обед / полдник}* - с помощью этой команды вы можете заказать питание\n'
|
||||||
|
'*/today* - команда выдающая меню на сегодня\n'
|
||||||
|
'*/tomorrow* - команда выдающая меню на завтра', types.ParseMode.MARKDOWN)
|
||||||
|
|
||||||
|
|
||||||
|
# ОТДЕЛЕНИЕ ДНЯ В ГРУППЕ
|
||||||
|
async def time(wait_for):
|
||||||
|
while True:
|
||||||
|
await asyncio.sleep(wait_for)
|
||||||
|
|
||||||
|
hour = dt.datetime.now().hour
|
||||||
|
date = dt.datetime.now().day
|
||||||
|
wkd = dt.datetime.today().weekday()
|
||||||
|
|
||||||
|
file = open('day.txt', 'r')
|
||||||
|
data = file.read()
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
if date != int(data) and hour == 10:
|
||||||
|
if wkd == 5:
|
||||||
|
await bot.send_message(chat_id=base.GROUP_ID,
|
||||||
|
text=f'<b>Питание на {".".join(reversed(str(dt.date.today() + dt.timedelta(days=2)).split("-")))}</b>',
|
||||||
|
parse_mode=types.ParseMode.HTML)
|
||||||
|
elif wkd != 6:
|
||||||
|
await bot.send_message(chat_id=base.GROUP_ID,
|
||||||
|
text=f'<b>Питание на {".".join(reversed(str(dt.date.today() + dt.timedelta(days=1)).split("-")))}</b>',
|
||||||
|
parse_mode=types.ParseMode.HTML)
|
||||||
|
|
||||||
|
file = open('day.txt', 'w')
|
||||||
|
file.write(str(date))
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.create_task(time(60)) # ПРОВЕРКА КАЖДУЮ МИНУТУ
|
||||||
|
executor.start_polling(dp, skip_updates=True)
|
||||||
1
day.txt
Normal file
1
day.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
0
|
||||||
47
pars.py
Normal file
47
pars.py
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import requests as req
|
||||||
|
import datetime as dt
|
||||||
|
import openpyxl, os
|
||||||
|
|
||||||
|
|
||||||
|
def eating(day):
|
||||||
|
if day == 0:
|
||||||
|
wkd = dt.datetime.today().weekday()
|
||||||
|
else:
|
||||||
|
wkd = (dt.date.today() + dt.timedelta(days=1)).weekday()
|
||||||
|
|
||||||
|
if wkd != 6:
|
||||||
|
try:
|
||||||
|
resp = req.get('http://school09.ru/vse-stati/main/food1').text
|
||||||
|
soup = BeautifulSoup(resp, "html.parser").find_all("ul", "easyfolderlisting")[0]
|
||||||
|
|
||||||
|
food = [[str(_)[15:32], str(_)[190:200], str(_)[130:172]] for _ in soup if _ != "\n"]
|
||||||
|
if day == 0:
|
||||||
|
eat = [_[2] for _ in food if _[0] == 'A Microsoft Excel' and _[1] == str(dt.date.today())][0]
|
||||||
|
else:
|
||||||
|
eat = [_[2] for _ in food if _[0] == 'A Microsoft Excel' and _[1] == str(dt.date.today() + dt.timedelta(days=1))][0]
|
||||||
|
|
||||||
|
file, xls = open("school_food.xlsx", "wb"), req.get(eat)
|
||||||
|
file.write(xls.content)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
excel_file = openpyxl.load_workbook('school_food.xlsx')
|
||||||
|
employees_sheet = excel_file['Лист1']
|
||||||
|
|
||||||
|
food = {employees_sheet["A4"].value: [], employees_sheet["A12"].value: [], employees_sheet["A21"].value: []}
|
||||||
|
|
||||||
|
for j in [[employees_sheet["A4"].value, 4, 7], [employees_sheet["A12"].value, 12, 8],
|
||||||
|
[employees_sheet["A21"].value, 21, 2]]:
|
||||||
|
for i in range(j[2]):
|
||||||
|
if employees_sheet[f"D{j[1] + i}"].value is None:
|
||||||
|
break
|
||||||
|
food[j[0]].append([employees_sheet[f"D{j[1] + i}"].value,
|
||||||
|
[employees_sheet[f"E{j[1] + i}"].value, employees_sheet[f"J{j[1] + i}"].value]])
|
||||||
|
|
||||||
|
os.remove("school_food.xlsx")
|
||||||
|
|
||||||
|
return food
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
Loading…
Add table
Reference in a new issue