chat_moderator_bot/utils/defs.py
2024-07-17 23:35:45 +03:00

44 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import logging
from aiogram.types import Message
import pandas
from utils.db import Postgres
async def delete_msg(msg: Message) -> None:
"""
Безопасно удаляет сообщение
:param msg: Message
:return: True, если текст является ссылкой, иначе False.
"""
try:
await msg.delete()
except:
pass
async def create_xlsx() -> str:
"""
Составляет xlsx файл с данными бан слова
:return: Путь к готовому xlsx файлу
"""
try:
p = Postgres()
ban_words = await p.get_data(
table_name='ban_words'
)
table_dict = {'ID': [], 'Слово': []}
for ban_word in ban_words:
table_dict['ID'].append(ban_word['id'])
table_dict['Слово'].append(ban_word['word'])
df = pandas.DataFrame(table_dict)
file_path = 'data/ban_words.xlsx'
df.to_excel(file_path, index=False)
return file_path
except Exception as e:
logging.error('Ошибка в create_xlsx', e)