Skip to content

Instantly share code, notes, and snippets.

View Glukhoff's full-sized avatar
😉
👨🏼‍💻 Backend Developer

Glukhov Sergey Glukhoff

😉
👨🏼‍💻 Backend Developer
View GitHub Profile
async def main():
config: Config = load_conf()
bot = Bot(token=config.telegram.token)
dp = Dispatcher()
dp.message.middleware(DataBaseMiddleware(config))
dp.include_router(start_commands.router)
dp.include_router(bot_join_in_group.router)
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker, declarative_base
Base = declarative_base()
def create_poll(user: str, password: str, host: str, name: str) -> sessionmaker:
engine = create_async_engine(
f"postgresql+asyncpg://{user}:{password}@{host}/{name}",
from typing import Callable, Any, Awaitable, Dict
from aiogram import BaseMiddleware
from aiogram.types import CallbackQuery
from bot.data.config import Config
from bot.models.base import create_poll
class DataBaseMiddleware(BaseMiddleware):
sql = update(TrackedAccounts) \
.where(TrackedAccounts.auth_key == deep_link_key) \
.values(
is_active=True,
chat_id=chat_id,
auth_key=None,
updated_at=datetime.fromisoformat(datetime.now().isoformat()),
).returning(TrackedAccounts.id)
async with db_session() as session:
@admin.register(models.OwnersDetails)
class OwnersDetailsAdmin(admin.ModelAdmin):
list_filter = ("name_organization",)
search_fields = ["name_organization", "inn_organization"]
list_display = ["get_sn", "inn_organization", "name_organization", "first_name", "last_name"]
inlines = [DeviceInline, RepairOrderInline]
@display(ordering='device__serial_number', description='Device')
def get_sn(self, obj):
return obj.device.serial_number
class OwnersDetails(models.Model):
first_name = models.CharField(verbose_name="Фамилия", max_length=50, blank=True)
last_name = models.CharField(verbose_name="Имя", max_length=50, blank=True)
name_organization = models.CharField(verbose_name="Наименование организации", max_length=150, blank=True)
inn_organization = models.BigIntegerField(verbose_name="ИНН организации", blank=True)
person_number_phone = models.BigIntegerField(verbose_name="Номер телефона", blank=True)
city = models.CharField(verbose_name="Город", max_length=100, blank=True)
street = models.CharField(verbose_name="Улица", max_length=100, blank=True)
house_number = models.CharField(verbose_name="Номер дома / офиса", max_length=50, blank=True)
import json
import time
import network
from machine import Pin
class WIFI:
def __init__(self):
self.wlan = network.WLAN(network.STA_IF)