pof

Proof of Freshness: collate proof of an authorship date.

Log | Files | << Repositories


tree c456092c80e9bc1c00f9d61d99b5ba3d8d7d239e
parent c9402b4fae05639485cc8294fbee730b7dedc7e9
author esote <esote.net@gmail.com> 1563399050 -0500
committer esote <esote.net@gmail.com> 1563399050 -0500
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iHUEABYIAB0WIQTXAxYDuIzimYoNSPuhTmRAjzzC8gUCXS+TsQAKCRChTmRAjzzC
 8nqxAQDcw/ARbsE5EcqMhknaIw/v7hgj3DsCORDegqen4/Ci0wEAnu2b+t2dhqz3
 DKgiLyVNAd/1XcIvKqPMdNF8df1iTQE=
 =eVtH
 -----END PGP SIGNATURE-----

Clean RSS parser struct, trim news strings

 pof.go | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/pof.go b/pof.go
index 088f419..60193ad 100644
--- a/pof.go
+++ b/pof.go
@@ -10,6 +10,7 @@ import (
 	"net/http"
 	"regexp"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -34,13 +35,8 @@ func main() {
 
 // Structure of an RSS feed, exposing only the fields useful to print news().
 type Rss struct {
-	XMLName xml.Name `xml:"rss"`
-	Channel struct {
-		Title string `xml:"title"`
-		Items []struct {
-			Title string `xml:"title"`
-		} `xml:"item"`
-	} `xml:"channel"`
+	Name   string   `xml:"channel>title"`
+	Titles []string `xml:"channel>item>title"`
 }
 
 // International news feeds.
@@ -64,14 +60,16 @@ func news() error {
 			return err
 		}
 
-		if len(rss.Channel.Items) < count {
-			return fmt.Errorf("couldn't find %d items", count)
+		if len(rss.Titles) < count {
+			return fmt.Errorf("couldn't find %d articles", count)
 		}
 
-		fmt.Printf("Src: %s (%s)\n ---\n", re.ReplaceAllString(rss.Channel.Title, " "), url)
+		fmt.Printf("Src: %s (%s)\n ---\n",
+			strings.TrimSpace(re.ReplaceAllString(rss.Name, " ")),
+			url)
 
 		for i := 0; i < count; i++ {
-			fmt.Printf("%s\n", re.ReplaceAllString(rss.Channel.Items[i].Title, " "))
+			fmt.Println(strings.TrimSpace(re.ReplaceAllString(rss.Titles[i], " ")))
 		}
 
 		fmt.Println()
@@ -80,7 +78,7 @@ func news() error {
 	return nil
 }
 
-// GET and unmarshal specified RSS URL.
+// GET and unmarshal RSS URL.
 func parseRss(url string) (*Rss, error) {
 	data, err := getRead(url)