parse html from rss feed

This commit is contained in:
Aaron Bieber 2023-02-16 08:25:50 -07:00
parent 0a6c5ee38a
commit 52da2c5bb1
No known key found for this signature in database
4 changed files with 33 additions and 9 deletions

View File

@ -16,7 +16,7 @@
in { in {
xintray = pkgs.buildGoModule { xintray = pkgs.buildGoModule {
pname = "xintray"; pname = "xintray";
version = "v0.1.6"; version = "v0.1.7";
src = ./.; src = ./.;
vendorSha256 = vendorSha256 =

2
go.mod
View File

@ -5,6 +5,7 @@ go 1.17
require ( require (
fyne.io/fyne/v2 v2.3.1 fyne.io/fyne/v2 v2.3.1
golang.org/x/crypto v0.6.0 golang.org/x/crypto v0.6.0
golang.org/x/net v0.6.0
) )
require ( require (
@ -31,7 +32,6 @@ require (
github.com/yuin/goldmark v1.5.3 // indirect github.com/yuin/goldmark v1.5.3 // indirect
golang.org/x/image v0.3.0 // indirect golang.org/x/image v0.3.0 // indirect
golang.org/x/mobile v0.0.0-20221110043201-43a038452099 // indirect golang.org/x/mobile v0.0.0-20221110043201-43a038452099 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect golang.org/x/text v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect

View File

@ -172,7 +172,11 @@ func (x *xinStatus) updateRepoInfo() error {
if err = xml.NewDecoder(res.Body).Decode(&resp); err != nil { if err = xml.NewDecoder(res.Body).Decode(&resp); err != nil {
return err return err
} }
x.repoCommit = resp.LatestHash() cmit, err := resp.LatestHash()
if err != nil {
return err
}
x.repoCommit = *cmit
} }
return nil return nil

32
rss.go
View File

@ -2,9 +2,10 @@ package main
import ( import (
"encoding/xml" "encoding/xml"
"html"
"strings" "strings"
"time" "time"
"golang.org/x/net/html"
) )
type Feed struct { type Feed struct {
@ -51,11 +52,30 @@ type Feed struct {
} `xml:"entry"` } `xml:"entry"`
} }
func (f *Feed) LatestHash() commit { func (f *Feed) LatestHash() (*commit, error) {
return commit{ doc, err := html.Parse(strings.NewReader(f.Entry[0].Content.Text))
if err != nil {
return nil, err
}
cmitMsg := ""
var h func(*html.Node)
h = func(n *html.Node) {
if n.Type == html.ElementNode && n.Data == "pre" {
cmitMsg = n.FirstChild.Data
return
}
for child := n.FirstChild; child != nil; child = child.NextSibling {
h(child)
}
}
h(doc)
return &commit{
hash: strings.Split(f.Entry[0].ID, "/")[1], hash: strings.Split(f.Entry[0].ID, "/")[1],
// TODO: use x/html to pull out the info? // TODO: use x/html to pull out the info?
message: html.UnescapeString(f.Entry[0].Content.Text), message: cmitMsg,
date: f.Entry[0].Updated, //message: html.UnescapeString(f.Entry[0].Content.Text),
} date: f.Entry[0].Updated,
}, nil
} }