From 7f26740f4c4905cad6b71ea749b83fa5a51c1a0f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 22 May 2025 23:41:54 +0000 Subject: feat: Add OPML import functionality via CLI This change introduces the ability to import feeds from an OPML file using a command-line interface. Key features: - New `--import-opml` (or `-I`) flag in `main.go` to specify the OPML file path. - The `importer.ImportOPML` function in `importer/importer.go` handles the parsing of the OPML file (using `github.com/gilliek/go-opml`) and addition of new feeds to the database. - Recursive processing of OPML outlines allows for importing feeds nested within folders. - Feeds are identified by their XML URL; existing feeds with the same URL are skipped to avoid duplicates. - Title extraction prioritizes the `title` attribute, then the `text` attribute of an outline, and falls back to "Untitled Feed". Comprehensive unit tests have been added in `importer/importer_test.go` to verify: - Correct parsing and importing of various OPML structures. - Proper handling of duplicate feeds (skipping). - Correct title extraction logic. - Database interaction and cleanup. --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index d121deb..4525846 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "adammathes.com/neko/config" "adammathes.com/neko/crawler" "adammathes.com/neko/exporter" + "adammathes.com/neko/importer" "adammathes.com/neko/models" "adammathes.com/neko/models/feed" "adammathes.com/neko/vlog" @@ -17,7 +18,7 @@ var Version, Build string func main() { var help, update, verbose, proxyImages bool - var configFile, dbfile, newFeed, export, password string + var configFile, dbfile, newFeed, export, password, importOPMLFile string var port, minutes int // config file @@ -28,6 +29,7 @@ func main() { flag.BoolVarP(&update, "update", "u", false, "fetch feeds and store new items") flag.StringVarP(&newFeed, "add", "a", "", "add the feed at URL `http://example.com/rss.xml`") flag.StringVarP(&export, "export", "x", "", "export feed. format required: text, opml, html, or json") + flag.StringVarP(&importOPMLFile, "import-opml", "I", "", "import feeds from an OPML file at `filepath`") // options -- defaults are set in config/main.go and overridden by cmd line flag.StringVarP(&dbfile, "database", "d", "", "sqlite database file") @@ -72,6 +74,12 @@ func main() { models.InitDB() + if importOPMLFile != "" { + vlog.Printf("importing feeds from OPML file %s\n", importOPMLFile) + importer.ImportOPML(importOPMLFile) + return // Exit after import + } + if update { vlog.Printf("starting crawl\n") crawler.Crawl() -- cgit v1.2.3