Skip to content

Instantly share code, notes, and snippets.

@Birdi7
Birdi7 / code.py
Last active September 15, 2023 10:13
aiogram to sync. author: @JrooTJunior
Save New Duplicate & Edit Just Text Twitter
"""
This example is under the same license as aiogram itself.
https://github.com/aiogram/aiogram/blob/dev-3.x/LICENSE
"""
from os import getenv
from typing import Any, Dict, Tuple
from asgiref.sync import async_to_sync
bot = Bot('ABC')
async_to_sync(bot.send_message)(
chat_id='123', text='abc
)
# берет хтмл из grades на my.university.innopolis.ru,
# и считает гпа по формуле (grades * credits)/credits.
# положить файлик рядом с main.py под именем gpa.html
# КАЧАЙ html из https://my.university.innopolis.ru/profile/personal-form/index?tab=validations
from bs4 import BeautifulSoup
with open("gpa.html", "r") as f:
html_doc = f.read()
from aiogram import Bot, Dispatcher, executor
import logging
from aiogram.contrib.fsm_storage.memory import MemoryStorage
logging.basicConfig(level=logging.INFO)
token = 'BOT_TOKEN_HERE'
bot = Bot(token)
dp = Dispatcher(bot, storage=MemoryStorage())
import warnings
def my_depr_func(user=None, **kwargs):
if 'user_id' in kwargs:
user = kwargs.pop('user_id')
warnings.simplefilter('always', DeprecationWarning)
warnings.warn("message", category=DeprecationWarning)
warnings.simplefilter('default', DeprecationWarning)
@Birdi7
Birdi7 / aiogram_chat_action_example.py
Created August 14, 2019 22:46
Example of chat action
"""
This is a echo bot.
It echoes any incoming text messages.
"""
import logging
from aiogram import Bot, Dispatcher, executor, types
API_TOKEN = 'BOT_API_TOKEN'
@Birdi7
Birdi7 / aiogram_wrapped_bug.py
Created July 29, 2019 18:54
A listing to show the bug in aiogram with wrapped functions
import functools
import logging
from typing import Coroutine
from aiogram import Bot, Dispatcher, executor, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
API_TOKEN = 'BOT_TOKEN_HERE'
# Configure logging
logging.basicConfig(level=logging.INFO)
@Birdi7
Birdi7 / aiogram_text_filter_bug.py
Last active July 18, 2019 20:09
Aiogram Text bug listing
from aiogram import Bot, Dispatcher, executor, types
from aiogram.dispatcher.filters.builtin import Text
API_TOKEN = 'BOT_TOKEN'
# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
import logging
import asyncio
from pathlib import Path
from typing import Optional
from aiogram import Bot, Dispatcher, executor, types
from aiogram.utils.exceptions import TelegramAPIError
from aiogram.types import InlineKeyboardMarkup
from aiogram.contrib.fsm_storage.files import JSONStorage
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
@Birdi7
Birdi7 / callback_data_factory_simple.py
Last active March 21, 2024 17:48
A simple example of usage of callback data factory from aiogram
"""
This is a simple example of usage of CallbackData factory
For more comprehensive example see callback_data_factory.py
"""
import asyncio
import logging
from aiogram import Bot, Dispatcher, executor, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage