aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorgoogle-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>2025-05-22 23:41:54 +0000
committergoogle-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>2025-05-22 23:41:54 +0000
commit7f26740f4c4905cad6b71ea749b83fa5a51c1a0f (patch)
tree89d40fd313f2b64f262b31690925e5f7aa461a5f /main.go
parentfd747e166a1f1a1f22a27e44810836b2bd2244c7 (diff)
downloadneko-7f26740f4c4905cad6b71ea749b83fa5a51c1a0f.tar.gz
neko-7f26740f4c4905cad6b71ea749b83fa5a51c1a0f.tar.bz2
neko-7f26740f4c4905cad6b71ea749b83fa5a51c1a0f.zip
feat: Add OPML import functionality via CLIopml-import-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.
Diffstat (limited to 'main.go')
-rw-r--r--main.go10
1 files changed, 9 insertions, 1 deletions
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()