show boosts

master
magical 2021-12-31 22:28:06 +00:00
parent 2182e4e739
commit df2ebd5b6a
2 changed files with 10 additions and 6 deletions

10
main.go
View File

@ -20,7 +20,7 @@ func main() {
var sources = []*FeedSource{ // TODO: interface Source var sources = []*FeedSource{ // TODO: interface Source
NewFeed("https://tilde.team/~dozens/dreams/rss.xml"), 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/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) ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
@ -52,10 +52,14 @@ func main() {
fmt.Println(src.Title, src.Error, src.LastStatus) fmt.Println(src.Title, src.Error, src.LastStatus)
for i, x := range src.Items { for i, x := range src.Items {
if i > 5 { if i > 5 {
break //break
}
auth := ""
if x.IsBoost {
auth = "RT @" + x.Author + ": "
} }
d, _ := time.Parse(time.RFC3339, x.PublishedString) 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)
} }
} }

View File

@ -45,8 +45,6 @@ const maxResponseSize = 1e6 // 1MB
// timestamp link. Within h-card, represents the profile permalink. // timestamp link. Within h-card, represents the profile permalink.
// Attached to display name link. // Attached to display name link.
// //
//
//
// Datetime properties (dt-*) // Datetime properties (dt-*)
// //
// dt-published // dt-published
@ -83,6 +81,7 @@ type MastoItem struct {
Link string `json:"link,omitempty"` Link string `json:"link,omitempty"`
PublishedString string `json:"published,omitempty"` PublishedString string `json:"published,omitempty"`
Author string `json:"author,omitempty"` Author string `json:"author,omitempty"`
IsBoost bool `json:"is_boost,omitempty"`
} }
func NewMastoSource(url string) *MastoSource { func NewMastoSource(url string) *MastoSource {
@ -160,7 +159,7 @@ func parseMicroformats(r io.Reader) (*MastoFeed, error) {
return nil, fmt.Errorf("no feed content found") return nil, fmt.Errorf("no feed content found")
} }
feed.Title = doc.Find(".h-feed > .p-name").First().AttrOr("value", "") 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"))) cw := strings.TrimSpace(text(elem.Find(".p-summary")))
if cw != "" { if cw != "" {
cw = "[" + cw + "] " cw = "[" + cw + "] "
@ -171,6 +170,7 @@ func parseMicroformats(r io.Reader) (*MastoFeed, error) {
Link: elem.Find("a.u-url.u-uid").AttrOr("href", ""), Link: elem.Find("a.u-url.u-uid").AttrOr("href", ""),
Author: text(elem.Find(".p-author .p-name")), Author: text(elem.Find(".p-author .p-name")),
PublishedString: elem.Find("data.dt-published").AttrOr("value", ""), PublishedString: elem.Find("data.dt-published").AttrOr("value", ""),
IsBoost: elem.HasClass("h-cite"),
}) })
}) })
return feed, nil return feed, nil