Started to use replit with aiogram. When running main.py, I get error: Temporary failure in name resolution. At the same time, on the local server, main.py runs fine
import keep_alive
from aiogram import Bot, Dispatcher, executor, types, asyncio
import requests
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
import pandas as pd
import time
API_TOKEN = 'TOKEN'
URL = 'https://kbp.by/rasp/timetable/view_beta_kbp/?page=stable&cat=group&id=49'
ADMIN_ID = 750896683
MAIN_CHAT_ID = 750896683
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
def saveDataFrame():
headers = {
'user-agent':
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.174 '
'YaBrowser/22.1.3.942 Yowser/2.5 Safari/537.36',
'accept':
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,'
'application/signed-exchange;v=b3;q=0.9 '
}
response = requests.get(URL, headers=headers)
html_content = response.text
soup = BeautifulSoup(html_content, 'html.parser')
table = soup.find('table')
df = pd.read_html(str(table))[0]
df.reset_index(drop=True, inplace=True)
df.index = df.index + 1
df = df.drop(df.columns[0], axis=1)
df = df.drop(df.columns[6], axis=1)
classlist = [
'Урок снят', 'ОхранаТруда', 'АрифмЛог', 'ИнструментПО', 'ОАиП',
'ЗащНасТерЧС', 'Математика', 'Практика', 'ФизКультура',
'Теория вероятностей', 'ТРПО', 'АнглЯз', 'СистемПО', 'ОснИдеолБГ',
'КураторЧас'
]
oldlist = [
r'\bОхранаТруда \b', r'\bАрифмЛогВТ \b', r'\bИнтруме \b', r'\bОАиП \b',
r'\bЗащНасТерЧС \b', r'\bМатематика \b', r'\bПрактРабПроф \b',
r'\bФизКультура\b', r'\bТеорВерМатСт \b', r'\bТРПО \b',
r'\bИнЯзПро \b', r'\bСистемПО \b', r'\bОснИдеолБГ \b',
r'\bКураторЧас \b'
]
newlist = [
'ОхранаТруда', 'АрифмЛог', 'ИнструментПО', 'ОАиП', 'ЗащНасТерЧС',
'Математика', 'Практика', 'ФизКультура', 'Теория вероятностей', 'ТРПО',
'АнглЯз', 'СистемПО', 'ОснИдеолБГ', 'КураторЧас'
]
for i in range(len(oldlist)):
df.replace(oldlist[i], newlist[i] + '\n', regex=True, inplace=True)
df.rename(columns={'Показать замены': 'Замены есть'}, inplace=True)
df = df.fillna('-')
for column_name in df.columns:
for row_index, row in df.iterrows():
column_index = df.columns.get_loc(column_name)
s = df.iloc[row_index - 1, column_index]
start_index = None
end_index = None
for firstword in classlist:
if firstword in s:
start_index = s.index(firstword) + len(firstword)
g = s[start_index:]
for secondword in classlist:
if secondword in g:
end_index = start_index + g.index(secondword)
break
if start_index is not None and end_index is not None:
s = s[end_index:]
break
start_index = None
end_index = None
for firstword in classlist:
if firstword in s:
start_index = s.index(firstword) + len(firstword)
g = s[start_index:]
for secondword in classlist:
if secondword in g:
end_index = start_index + g.index(secondword)
break
if start_index is not None and end_index is not None:
s = s[end_index:]
break
df.iat[row_index - 1, column_index] = s
df.replace(r'\b Т-193\b', '', regex=True, inplace=True)
df.replace(r'\bТ-193 \b', '', regex=True, inplace=True)
teacherlist = [r'\bАхрамович \b', r'\bРогалевич А\b', r'\bМилашевски\b']
newteacherlist = ['', 'Рогалевич А.В.', 'Милашевский А.Д.']
for i in range(len(teacherlist)):
df.replace(teacherlist[i], newteacherlist[i], regex=True, inplace=True)
return df
def savePhoto(df):
fig, ax = plt.subplots(figsize=(22, 16))
ax.axis('off')
table_img = pd.plotting.table(ax,
df,
loc='center',
cellLoc='center',
colWidths=[0.15] * len(df.columns))
table_img.auto_set_font_size(False)
table_img.set_fontsize(12)
table_img.scale(2, 6)
plt.savefig('timetable.png', bbox_inches='tight', pad_inches=0.2)
@dp.message_handler(commands=['timetable'])
async def cmd_timetable(message: types.Message):
df = saveDataFrame()
savePhoto(df)
photo = open('./timetable.png', 'rb')
await bot.send_photo(message.chat.id,
photo,
reply_to_message_id=message.message_id)
@dp.message_handler(commands=['mute'])
async def cmd_mute(message: types.Message):
if message.from_user.id == ADMIN_ID:
await bot.delete_message(message.chat.id, message.message_id)
command_args = message.get_args()
if message.reply_to_message and command_args:
user_id = message.reply_to_message.from_user
permissions = {
'can_send_messages': False,
'can_send_media_messages': False,
'can_send_other_messages': False,
'can_add_web_page_previews': False
}
end_time = int(time.time()) + (int(command_args) * 60)
chat_permissions = types.ChatPermissions(**permissions)
await bot.restrict_chat_member(message.chat.id, user_id.id,
chat_permissions, end_time)
await bot.send_message(
message.from_user.id, 'Пользователю ' + user_id.username +
' успешно выдан мут на ' + command_args + ' минут.')
async def checktimetable(df):
while True:
if str(df) != str(saveDataFrame()):
df = saveDataFrame()
savePhoto(df)
photo = open('./timetable.png', 'rb')
await bot.send_photo(MAIN_CHAT_ID, photo)
await asyncio.sleep(900)
async def on_startup(x):
asyncio.create_task(checktimetable(saveDataFrame()))
if __name__ == '__main__':
keep_alive.keep_alive()
executor.start_polling(dp, skip_updates=True, on_startup=on_startup)