Add -S flag for specifying a file with feed URLs

This commit is contained in:
skuzzymiglet 2020-11-18 22:08:39 +00:00 committed by Drew DeVault
parent af9038b5bb
commit f13edb5dfd

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"bufio"
"html" "html"
"html/template" "html/template"
"io/ioutil" "io/ioutil"
@ -51,6 +52,7 @@ func main() {
narticles = getopt.Int("n", 3, "article count") narticles = getopt.Int("n", 3, "article count")
perSource = getopt.Int("p", 1, "articles to take from each source") perSource = getopt.Int("p", 1, "articles to take from each source")
summaryLen = getopt.Int("l", 256, "length of summaries") summaryLen = getopt.Int("l", 256, "length of summaries")
urlsFile = getopt.String("S", "", "file with URLs of sources")
sources []*url.URL sources []*url.URL
) )
getopt.Var((*urlSlice)(&sources), "s", "list of sources") getopt.Var((*urlSlice)(&sources), "s", "list of sources")
@ -65,6 +67,18 @@ func main() {
panic(err) panic(err)
} }
if *urlsFile != "" {
file, err := os.Open(*urlsFile)
if err != nil {
panic(err)
}
sc := bufio.NewScanner(file)
for sc.Scan() {
(*urlSlice)(&sources).Set(sc.Text())
}
file.Close()
}
input, err := ioutil.ReadAll(os.Stdin) input, err := ioutil.ReadAll(os.Stdin)
if err != nil { if err != nil {
panic(err) panic(err)