package main import ( "fmt" "log/slog" "os" "strconv" "github.com/gocolly/colly/v2" ) // ToDo: emoji in text support // ToDo: attachment support? // ToDo: polls support? type Status struct { Username string DisplayName string ProfileURL string AvatarURL string Text string Published string ReplyCount int FavouriteCount int BoostCount int } func main() { if len(os.Args) != 2 { fmt.Fprintf(os.Stderr, "Usage: %s \n", os.Args[0]) os.Exit(1) } url := os.Args[1] c := colly.NewCollector() c.OnHTML("article.status", func(e *colly.HTMLElement) { replyCount, _ := strconv.Atoi(e.ChildText("aside.status-info div[title=Replies] dd")) favouriteCount, _ := strconv.Atoi(e.ChildText("aside.status-info div[title=Faves] dd")) boostCount, _ := strconv.Atoi(e.ChildText("aside.status-info div[title=Boosts] dd")) status := &Status{ Username: e.ChildText("address div.author-strap span.username"), DisplayName: e.ChildText("address div.author-strap span.displayname"), ProfileURL: e.ChildAttr("address a", "href"), AvatarURL: e.ChildAttr("address img.avatar", "src"), Text: e.ChildText("div.status-body div.content"), Published: e.ChildAttr("aside.status-info div.published-at time", "datetime"), ReplyCount: replyCount, FavouriteCount: favouriteCount, BoostCount: boostCount, } slog.Info("Status", "status", status) }) c.Visit(url) }