mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
Add --news to --print
This commit is contained in:
parent
f9723f67b7
commit
8dd08327b1
2 changed files with 55 additions and 0 deletions
2
cmd.go
2
cmd.go
|
@ -318,6 +318,8 @@ func handlePrint() (err error) {
|
|||
err = printNumberOfUpdates()
|
||||
case cmdArgs.existsArg("u", "upgrades"):
|
||||
err = printUpdateList(cmdArgs)
|
||||
case cmdArgs.existsArg("w", "news"):
|
||||
err = printNewsFeed()
|
||||
case cmdArgs.existsArg("c", "complete"):
|
||||
switch {
|
||||
case cmdArgs.existsArg("f", "fish"):
|
||||
|
|
53
print.go
53
print.go
|
@ -1,7 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -398,6 +402,55 @@ outer:
|
|||
return nil
|
||||
}
|
||||
|
||||
type item struct {
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
PubDate string `xml:"pubDate"`
|
||||
Creator string `xml:"dc:creator"`
|
||||
}
|
||||
|
||||
type channel struct {
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
Language string `xml:"language"`
|
||||
Lastbuilddate string `xml:"lastbuilddate"`
|
||||
Item []item `xml:"item"`
|
||||
}
|
||||
|
||||
type rss struct {
|
||||
Channel channel `xml:"channel"`
|
||||
}
|
||||
|
||||
func printNewsFeed() error {
|
||||
resp, err := http.Get("https://archlinux.org/feeds/news")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rss := rss{}
|
||||
|
||||
p := xml.NewDecoder(bytes.NewReader(body))
|
||||
|
||||
err = p.Decode(&rss)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, item := range rss.Channel.Item {
|
||||
fmt.Println(item.PubDate, item.Title)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Formats a unix timestamp to ISO 8601 date (yyyy-mm-dd)
|
||||
func formatTime(i int) string {
|
||||
t := time.Unix(int64(i), 0)
|
||||
|
|
Loading…
Reference in a new issue