From df2ebd5b6a325dbeb1bdc96bde84c703700ee0c4 Mon Sep 17 00:00:00 2001 From: magical Date: Fri, 31 Dec 2021 22:28:06 +0000 Subject: [PATCH] show boosts --- main.go | 10 +++++++--- mastodon.go | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 6947e4c..89d9af4 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ func main() { var sources = []*FeedSource{ // TODO: interface Source NewFeed("https://tilde.team/~dozens/dreams/rss.xml"), NewFeed("https://tilde.town/~magical/xkcd.xml"), // "https://xkcd.com/atom.xml", - NewFeed("https://tilde.town/~magical/404.xml"), + //NewFeed("https://tilde.town/~magical/404.xml"), } ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) @@ -52,10 +52,14 @@ func main() { fmt.Println(src.Title, src.Error, src.LastStatus) for i, x := range src.Items { if i > 5 { - break + //break + } + auth := "" + if x.IsBoost { + auth = "RT @" + x.Author + ": " } d, _ := time.Parse(time.RFC3339, x.PublishedString) - fmt.Println("\t", d.Format(time.Stamp), x.Content) + fmt.Println("\t", d.Format(time.Stamp), auth+x.Content) } } diff --git a/mastodon.go b/mastodon.go index cc21ad8..f3e7ed0 100644 --- a/mastodon.go +++ b/mastodon.go @@ -45,8 +45,6 @@ const maxResponseSize = 1e6 // 1MB // timestamp link. Within h-card, represents the profile permalink. // Attached to display name link. // -// -// // Datetime properties (dt-*) // // dt-published @@ -83,6 +81,7 @@ type MastoItem struct { Link string `json:"link,omitempty"` PublishedString string `json:"published,omitempty"` Author string `json:"author,omitempty"` + IsBoost bool `json:"is_boost,omitempty"` } func NewMastoSource(url string) *MastoSource { @@ -160,7 +159,7 @@ func parseMicroformats(r io.Reader) (*MastoFeed, error) { return nil, fmt.Errorf("no feed content found") } feed.Title = doc.Find(".h-feed > .p-name").First().AttrOr("value", "") - doc.Find(".h-feed .h-entry").Each(func(i int, elem *goquery.Selection) { + doc.Find(".h-feed").Find(".h-entry, .h-cite").Each(func(i int, elem *goquery.Selection) { cw := strings.TrimSpace(text(elem.Find(".p-summary"))) if cw != "" { cw = "[" + cw + "] " @@ -171,6 +170,7 @@ func parseMicroformats(r io.Reader) (*MastoFeed, error) { Link: elem.Find("a.u-url.u-uid").AttrOr("href", ""), Author: text(elem.Find(".p-author .p-name")), PublishedString: elem.Find("data.dt-published").AttrOr("value", ""), + IsBoost: elem.HasClass("h-cite"), }) }) return feed, nil