парсер

This commit is contained in:
Artem Tsyrulnikov
2026-01-06 21:04:42 +03:00
parent b77e4fd0b6
commit 2c0ae2dfc3
45 changed files with 2202 additions and 51 deletions

View File

@@ -0,0 +1,65 @@
package domain
import (
"fmt"
"github.com/google/uuid"
)
type Channel struct {
ID uuid.UUID
TelegramID int64
Username string
Title string
AccessHash int64
Pts int
}
const channelIDOffset int64 = 1000000000000
// ChannelID returns the positive channel identifier expected by Telegram API.
func (c Channel) ChannelID() int64 {
return ChannelIDFromChatID(c.TelegramID)
}
// ChannelIDFromChatID converts stored chat IDs (Bot API style) to channel IDs used by TDLib.
func ChannelIDFromChatID(chatID int64) int64 {
if chatID >= 0 {
return chatID
}
return -chatID - channelIDOffset
}
// ChatIDFromChannelID converts Telegram channel IDs to Bot API style chat IDs (-100...).
func ChatIDFromChannelID(channelID int64) int64 {
return -channelIDOffset - channelID
}
// NormalizeChatID ensures that TelegramID is stored in chat-id form (negative).
func NormalizeChatID(id int64) int64 {
if id < 0 {
return id
}
return ChatIDFromChannelID(id)
}
func (c Channel) String() string {
return fmt.Sprintf(
"Channel{id=%s telegram_id=%d username=%q title=%q access_hash=%d pts=%d}",
c.ID,
c.TelegramID,
c.Username,
c.Title,
c.AccessHash,
c.Pts,
)
}
type ChannelDiff struct {
NewPts int
NewPosts []Post
DeletedPosts []Post
UpdatedChannel *Channel
}

View File

@@ -0,0 +1,27 @@
package domain
import (
"fmt"
"github.com/google/uuid"
)
type Post struct {
ID uuid.UUID
ChannelID uuid.UUID
MessageID int
Text string
Link string
Views int
}
func NewPost(channel Channel, messageID int, text string, views int) Post {
return Post{
ID: uuid.New(),
ChannelID: channel.ID,
MessageID: messageID,
Text: text,
Link: fmt.Sprintf("https://t.me/%s/%d", channel.Username, messageID),
Views: views,
}
}

View File

@@ -0,0 +1,14 @@
package domain
import (
"time"
"github.com/google/uuid"
)
type ViewsSnapshot struct {
ViewsCount int
FetchedAt time.Time
PostID uuid.UUID
}