find empty categories

This commit is contained in:
Celogeek 2022-01-03 09:06:42 +01:00
parent da735d87ca
commit 28499d8dbd
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
2 changed files with 20 additions and 13 deletions

View File

@ -10,6 +10,7 @@ import (
type CategoriesListCommand struct {
Filter string `short:"x" long:"filter" description:"Regexp filter"`
Empty bool `short:"e" long:"empty" description:"Find empty album without any photo or sub album"`
}
func (c *CategoriesListCommand) Execute(args []string) error {
@ -28,22 +29,27 @@ func (c *CategoriesListCommand) Execute(args []string) error {
return err
}
filter := regexp.MustCompile("")
var filter *regexp.Regexp
if c.Filter != "" {
filter = regexp.MustCompile("(?i)" + c.Filter)
}
t := table.NewWriter()
t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"})
t.AppendHeader(table.Row{"Id", "Name", "Images", "Total Images", "Url"})
for _, category := range categories {
if filter.MatchString(category.Name) {
t.AppendRow(table.Row{
category.Id,
category.Name,
category.ImagesCount,
category.Url,
})
if filter != nil && !filter.MatchString(category.Name) {
continue
}
if c.Empty && category.TotalImagesCount != 0 {
continue
}
t.AppendRow(table.Row{
category.Id,
category.Name,
category.ImagesCount,
category.TotalImagesCount,
category.Url,
})
}
t.SetOutputMirror(os.Stdout)

View File

@ -3,10 +3,11 @@ package piwigotools
type Categories []*Category
type Category struct {
Id int `json:"id"`
Name string `json:"name"`
ImagesCount int `json:"nb_images"`
Url string `json:"url"`
Id int `json:"id"`
Name string `json:"name"`
ImagesCount int `json:"nb_images"`
TotalImagesCount int `json:"total_nb_images"`
Url string `json:"url"`
}
func (c *Categories) Names() []string {