Merge pull request #385 from PeachIceTea/newsfeed
Get arch package news using --print --news
This commit is contained in:
5 files changed
+63
-2
No files matched your search
@@ -91,6 +91,7 @@ Print specific options:
|
||||
-n --numberupgrades Print number of updates
|
||||
-s --stats Display system package statistics
|
||||
-u --upgrades Print update list
|
||||
-w --news Print arch news
|
||||
|
||||
Yay specific options:
|
||||
-c --clean Remove unneeded dependencies
|
||||
@@ -318,6 +319,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"):
|
||||
|
||||
+2
-2
@@ -65,8 +65,8 @@ _yay() {
|
||||
'c g i l p s u w y')
|
||||
upgrade=('asdeps asexplicit force needed nodeps assume-installed print recursive' 'p')
|
||||
yays=('clean gendb' 'c')
|
||||
print=('complete defaultconfig config numberupgrades stats upgrades' 'c d g n
|
||||
s u')
|
||||
print=('complete defaultconfig config numberupgrades stats upgrades news' 'c d g n
|
||||
s u w')
|
||||
common=('arch cachedir color config confirm dbpath debug gpgdir help hookdir logfile
|
||||
noconfirm noprogressbar noscriptlet quiet save mflags buildir editor
|
||||
makepkg pacman tar git gpg gpgflags config requestsplitn sudoloop nosudoloop
|
||||
|
||||
@@ -108,6 +108,7 @@ complete -c $progname -n $print -s d -l defaultconfig -d 'Print current yay conf
|
||||
complete -c $progname -n $print -s n -l numberupgrades -d 'Print number of updates' -f
|
||||
complete -c $progname -n $print -s s -l stats -d 'Display system package statistics' -f
|
||||
complete -c $progname -n $print -s u -l upgrades -d 'Print update list' -f
|
||||
complete -c $progname -n $print -s w -l news -d 'Print arch news'
|
||||
|
||||
# Transaction options (sync, remove, upgrade)
|
||||
for condition in sync remove upgrade
|
||||
|
||||
@@ -134,6 +134,7 @@ _pacman_opts_print_modifiers=(
|
||||
{-n,--numberupgrades}'[Print number of updates]'
|
||||
{-s,--stats}'[Display system package statistics]'
|
||||
{-u,--upgrades}'[Print update list]'
|
||||
{-w,--news}'[Print arch news]'
|
||||
)
|
||||
# options for passing to _arguments: options for --remove command
|
||||
_pacman_opts_remove=(
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -398,6 +402,58 @@ outer:
|
||||
return nil
|
||||
}
|
||||
|
||||
type rss struct {
|
||||
Channel struct {
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
Language string `xml:"language"`
|
||||
Lastbuilddate string `xml:"lastbuilddate"`
|
||||
Item []struct {
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
PubDate string `xml:"pubDate"`
|
||||
Creator string `xml:"dc:creator"`
|
||||
} `xml:"item"`
|
||||
} `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{}
|
||||
|
||||
d := xml.NewDecoder(bytes.NewReader(body))
|
||||
err = d.Decode(&rss)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, item := range rss.Channel.Item {
|
||||
date, err := time.Parse(time.RFC1123Z, item.PubDate)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fd := formatTime(int(date.Unix()))
|
||||
|
||||
fmt.Println(magenta(fd), strings.TrimSpace(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)
|
||||
|
||||
Reference in new issue
Block a user