ручное парсер
This commit is contained in:
@@ -11,19 +11,21 @@ import (
|
||||
)
|
||||
|
||||
func (d *Database) GetChannelsWithTrackedPosts(ctx context.Context) ([]domain.Channel, error) {
|
||||
query := `SELECT DISTINCT
|
||||
query := `SELECT DISTINCT
|
||||
c.id,
|
||||
c.telegram_id,
|
||||
c.username,
|
||||
c.title,
|
||||
c.access_hash,
|
||||
c.pts,
|
||||
c.invite_link
|
||||
c.invite_link,
|
||||
c.is_accessible
|
||||
FROM channel c
|
||||
INNER JOIN placement p ON p.channel_id = c.id
|
||||
INNER JOIN placement_post pp ON pp.placement_id = p.id
|
||||
INNER JOIN post po ON po.id = pp.post_id
|
||||
WHERE po.deleted_from_channel_at IS NULL;`
|
||||
WHERE po.deleted_from_channel_at IS NULL
|
||||
AND c.is_accessible = true;`
|
||||
|
||||
txOrPool := transaction.TryExtractTX(ctx)
|
||||
|
||||
@@ -50,13 +52,14 @@ WHERE po.deleted_from_channel_at IS NULL;`
|
||||
}
|
||||
|
||||
type getChannelsWithTrackedPostsDTO struct {
|
||||
ID pgtype.UUID
|
||||
TelegramID pgtype.Int8
|
||||
Username pgtype.Text
|
||||
Title pgtype.Text
|
||||
AccessHash pgtype.Int8
|
||||
Pts pgtype.Int4
|
||||
InviteLink pgtype.Text
|
||||
ID pgtype.UUID
|
||||
TelegramID pgtype.Int8
|
||||
Username pgtype.Text
|
||||
Title pgtype.Text
|
||||
AccessHash pgtype.Int8
|
||||
Pts pgtype.Int4
|
||||
InviteLink pgtype.Text
|
||||
IsAccessible pgtype.Bool
|
||||
}
|
||||
|
||||
func (dto *getChannelsWithTrackedPostsDTO) destination() []any {
|
||||
@@ -68,17 +71,19 @@ func (dto *getChannelsWithTrackedPostsDTO) destination() []any {
|
||||
&dto.AccessHash,
|
||||
&dto.Pts,
|
||||
&dto.InviteLink,
|
||||
&dto.IsAccessible,
|
||||
}
|
||||
}
|
||||
|
||||
func (dto *getChannelsWithTrackedPostsDTO) toDomain() domain.Channel {
|
||||
return domain.Channel{
|
||||
ID: dto.ID.Bytes,
|
||||
TelegramID: domain.NormalizeChatID(dto.TelegramID.Int64),
|
||||
Username: dto.Username.String,
|
||||
Title: dto.Title.String,
|
||||
AccessHash: dto.AccessHash.Int64,
|
||||
Pts: int(dto.Pts.Int32),
|
||||
InviteLink: dto.InviteLink.String,
|
||||
ID: dto.ID.Bytes,
|
||||
TelegramID: domain.NormalizeChatID(dto.TelegramID.Int64),
|
||||
Username: dto.Username.String,
|
||||
Title: dto.Title.String,
|
||||
AccessHash: dto.AccessHash.Int64,
|
||||
Pts: int(dto.Pts.Int32),
|
||||
InviteLink: dto.InviteLink.String,
|
||||
IsAccessible: dto.IsAccessible.Bool,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,9 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/TelegramExchange/pkg/transaction"
|
||||
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func (d *Database) UpdateChannel(ctx context.Context, channel domain.Channel) error {
|
||||
@@ -42,15 +40,6 @@ WHERE id = $1;`
|
||||
inviteLinkDTO = pgtype.Text{Valid: false}
|
||||
}
|
||||
|
||||
// Log warning if both identity fields are empty (will violate CHECK constraint)
|
||||
if !usernameDTO.Valid && !inviteLinkDTO.Valid {
|
||||
log.Warn().
|
||||
Str("channel_id", channel.ID.String()).
|
||||
Int64("telegram_id", channel.TelegramID).
|
||||
Str("title", channel.Title).
|
||||
Msg("UpdateChannel: both username and invite_link are empty, this may violate CHECK constraint")
|
||||
}
|
||||
|
||||
dto := updateChannelDTO{
|
||||
ID: pgtype.UUID{Bytes: channel.ID, Valid: true},
|
||||
TelegramID: pgtype.Int8{Int64: channel.TelegramID, Valid: true},
|
||||
|
||||
@@ -31,7 +31,7 @@ func (t *Telegram) GetChannelHistory(ctx context.Context, channel domain.Channel
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
placements := make([]domain.Post, 0, len(messages.Messages))
|
||||
posts := make([]domain.Post, 0, len(messages.Messages))
|
||||
|
||||
for _, raw := range messages.Messages {
|
||||
m, ok := raw.(*tg.Message)
|
||||
@@ -42,8 +42,8 @@ func (t *Telegram) GetChannelHistory(ctx context.Context, channel domain.Channel
|
||||
text := messageToHTML(m.Message, m.Entities)
|
||||
publishedAt := time.Unix(int64(m.Date), 0).UTC()
|
||||
p := domain.NewPost(channel, m.ID, text, m.Views, publishedAt)
|
||||
placements = append(placements, p)
|
||||
posts = append(posts, p)
|
||||
}
|
||||
|
||||
return placements, nil
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
|
||||
"github.com/google/uuid"
|
||||
"github.com/gotd/td/tg"
|
||||
)
|
||||
|
||||
@@ -49,7 +48,6 @@ func (t *Telegram) ParseChannelMeta(ctx context.Context, username string) (domai
|
||||
}
|
||||
|
||||
return domain.Channel{
|
||||
ID: uuid.New(),
|
||||
TelegramID: domain.ChatIDFromChannelID(ch.ID),
|
||||
Username: username,
|
||||
Title: ch.Title,
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
|
||||
"github.com/google/uuid"
|
||||
"github.com/gotd/td/telegram/deeplink"
|
||||
"github.com/gotd/td/tg"
|
||||
)
|
||||
@@ -64,12 +63,12 @@ func (t *Telegram) ParseChannelMetaByInvite(ctx context.Context, inviteLink stri
|
||||
}
|
||||
|
||||
return domain.Channel{
|
||||
ID: uuid.New(),
|
||||
TelegramID: domain.ChatIDFromChannelID(channel.ID),
|
||||
Username: username,
|
||||
Title: channel.Title,
|
||||
AccessHash: channel.AccessHash,
|
||||
Pts: pts,
|
||||
InviteLink: inviteLink,
|
||||
IsAccessible: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user