From cd1509967d7dafbf2d1a051206e368bd3aa5e179 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Sun, 8 Apr 2018 08:51:26 -0700 Subject: refactor exporter, add json/opml export formats --- main.go | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index b7aefb3..40f2647 100644 --- a/main.go +++ b/main.go @@ -3,30 +3,28 @@ package main import ( "adammathes.com/neko/config" "adammathes.com/neko/crawler" + "adammathes.com/neko/exporter" "adammathes.com/neko/models" "adammathes.com/neko/models/feed" "adammathes.com/neko/vlog" "adammathes.com/neko/web" - "encoding/xml" - "fmt" flag "github.com/ogier/pflag" ) func main() { - var serve, update, verbose, printFeeds, opml bool - var configFile, newFeed string + var serve, update, verbose bool + var configFile, newFeed, export string flag.StringVarP(&configFile, "config", "c", "config.json", "`configuration` file") flag.BoolVarP(&update, "update", "u", false, "fetch feeds and store them in the database") flag.BoolVarP(&serve, "serve", "s", false, "run http server") flag.BoolVarP(&verbose, "verbose", "v", false, "verbose output") - flag.BoolVarP(&printFeeds, "feeds", "f", false, "list all currently crawled feeds") - flag.BoolVarP(&opml, "opml", "o", false, "export feed list as opml") flag.StringVarP(&newFeed, "add", "a", "", "add the feed at URL `http://example.com/rss.xml`") + flag.StringVarP(&export, "export", "x", "", "export feeds as `text`, json or opml") flag.Parse() // no command - if !update && !serve && !printFeeds && !opml && newFeed == "" { + if !update && !serve && newFeed == "" && export == "" { flag.Usage() return } @@ -45,23 +43,7 @@ func main() { if newFeed != "" { feed.NewFeed(newFeed) } - if printFeeds { - feeds, err := feed.All() - if err != nil { - panic(err) - } - for _, f := range feeds { - fmt.Printf("%s\n", f.Url) - } - } - if opml { - feeds, _ := feed.All() - fmt.Printf(`neko feeds`) - fmt.Printf("\n") - for _, f := range feeds { - b, _ := xml.Marshal(f) - fmt.Printf("%s\n", string(b)) - } - fmt.Printf(``) + if export != "" { + exporter.ExportFeeds(export) } } -- cgit v1.2.3