парсер новый

This commit is contained in:
Artem Tsyrulnikov
2026-02-04 14:54:25 +03:00
parent 6fc6a60bce
commit d15f2d2bad
6 changed files with 187 additions and 10 deletions

View File

@@ -24,7 +24,7 @@ async def create_channels(self: 'Usecase', input: dto.CreateChannelsInput) -> dt
raise ValueError('Telegram channel not found by invite link')
parsed_username = parser_response.username or None
is_private = channel_input.invite_link != ""
is_private = channel_input.invite_link != ''
channel = await self.database.get_channel(telegram_id=parser_response.telegram_id)
if not channel and parsed_username:
@@ -34,9 +34,16 @@ async def create_channels(self: 'Usecase', input: dto.CreateChannelsInput) -> dt
if channel:
status = 'updated'
updated = False
# Канал стал публичным (появился username)
if parsed_username is not None and channel.username != parsed_username:
channel.username = parsed_username
channel.invite_link = None # Очищаем invite_link у публичных каналов
updated = True
# Канал остаётся приватным или обновляется
elif parsed_username is None and channel_input.invite_link and channel.invite_link != channel_input.invite_link:
channel.invite_link = channel_input.invite_link
updated = True
if parser_response.title is not None and channel.title != parser_response.title:
channel.title = parser_response.title
updated = True
@@ -49,12 +56,6 @@ async def create_channels(self: 'Usecase', input: dto.CreateChannelsInput) -> dt
if parser_response.pts is not None and channel.pts != parser_response.pts:
channel.pts = parser_response.pts
updated = True
if is_private and channel.pts != 0:
channel.pts = 0
updated = True
if channel_input.invite_link and channel.invite_link != channel_input.invite_link:
channel.invite_link = channel_input.invite_link
updated = True
if updated:
await self.database.update_channel(channel)
else:
@@ -64,7 +65,8 @@ async def create_channels(self: 'Usecase', input: dto.CreateChannelsInput) -> dt
title=parser_response.title,
access_hash=parser_response.access_hash,
pts=0 if is_private else parser_response.pts,
invite_link=channel_input.invite_link,
# Для публичных каналов (есть username) invite_link не храним
invite_link=None if parsed_username else channel_input.invite_link,
)
await self.database.create_channel(channel)