Adds list-categories command
This commit is contained in:
parent
b7d8b94d46
commit
8d7decd3f7
5 changed files with 61 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
/bin/
|
||||
/bookworm.json
|
||||
|
|
|
@ -17,3 +17,6 @@ an ebook using calibre.
|
|||
script.
|
||||
- If possible, the script should send the ebook to our reader, if
|
||||
possible (say, through the kindle email, for example).
|
||||
- Allow to download the OPML and use it as a local storage for the
|
||||
feeds. In the future, maybe users will send their OPMLs and Miniflux
|
||||
will not be necessary.
|
||||
|
|
|
@ -5,15 +5,27 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
miniflux "miniflux.app/client"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
MinifluxURL string `json:"miniflux_url"`
|
||||
MinifluxUsername string `json:"miniflux_username"`
|
||||
MinifluxPassword string `json:"miniflux_password"`
|
||||
MinifluxAPI string `json:"miniflux_api"`
|
||||
MinifluxCategory string `json:"miniflux_category"`
|
||||
}
|
||||
|
||||
func (c *Config) IsValid() error {
|
||||
if c.MinifluxURL == "" {
|
||||
return fmt.Errorf("miniflux_url is required")
|
||||
}
|
||||
|
||||
if c.MinifluxAPI == "" && (c.MinifluxUsername == "" || c.MinifluxPassword == "") {
|
||||
return fmt.Errorf("either miniflux_api or miniflux_username and miniflux_password need to be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -31,6 +43,21 @@ func ReadConfig(name string) (*Config, error) {
|
|||
return &cfg, nil
|
||||
}
|
||||
|
||||
func createClient(cfg *Config) (*miniflux.Client, error) {
|
||||
var client *miniflux.Client
|
||||
if cfg.MinifluxAPI != "" {
|
||||
client = miniflux.New(cfg.MinifluxURL, cfg.MinifluxAPI)
|
||||
} else {
|
||||
client = miniflux.New(cfg.MinifluxURL, cfg.MinifluxUsername, cfg.MinifluxPassword)
|
||||
}
|
||||
|
||||
if _, err := client.Me(); err != nil {
|
||||
return nil, fmt.Errorf("cannot get \"me\" with newly created client: %w", err)
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func checkErr(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
||||
|
@ -38,8 +65,25 @@ func checkErr(err error) {
|
|||
}
|
||||
}
|
||||
|
||||
func listCategories(cfg *Config, client *miniflux.Client) error {
|
||||
categories, err := client.Categories()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot fetch categories: %w", err)
|
||||
}
|
||||
|
||||
if len(categories) != 0 {
|
||||
fmt.Println("Category list")
|
||||
}
|
||||
for _, c := range categories {
|
||||
fmt.Printf("- %s\n", c.Title)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
cfgFlag := flag.String("config", "bookworm.json", "path to the configuration file")
|
||||
listCategoriesFlag := flag.Bool("list-categories", false, "lists the categories of the remote Miniflux instance")
|
||||
flag.Parse()
|
||||
|
||||
cfg, err := ReadConfig(*cfgFlag)
|
||||
|
@ -47,4 +91,13 @@ func main() {
|
|||
|
||||
cErr := cfg.IsValid()
|
||||
checkErr(cErr)
|
||||
|
||||
client, cliErr := createClient(cfg)
|
||||
checkErr(cliErr)
|
||||
|
||||
if *listCategoriesFlag {
|
||||
listCategories(cfg, client)
|
||||
}
|
||||
|
||||
// download feeds (filter by category if specified)
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
|||
module git.ctrlz.es/mgdelacroix/bookworm
|
||||
|
||||
go 1.21.9
|
||||
|
||||
require miniflux.app v1.0.46
|
||||
|
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
miniflux.app v1.0.46 h1:2/xrbXiEoQlj/bAZ8MT+fPN1+gmYDYuXVCOhvSskns4=
|
||||
miniflux.app v1.0.46/go.mod h1:YtEJIO1vMCvZgyzDbds7II0W/H7sGpo3auFCQscuMrE=
|
Loading…
Reference in a new issue