mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 10:12:37 +02:00
add parsing date, remap categories, improve try
This commit is contained in:
parent
ad8253ff18
commit
2247deac18
33
internal/piwigo/categories.go
Normal file
33
internal/piwigo/categories.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package piwigo
|
||||||
|
|
||||||
|
import "net/url"
|
||||||
|
|
||||||
|
type Categories struct {
|
||||||
|
Categories []Category `json:"categories"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Category struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
ImagesCount int `json:"nb_images"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Piwigo) Categories() (map[int]Category, error) {
|
||||||
|
var categories Categories
|
||||||
|
|
||||||
|
err := p.Post("pwg.categories.getList", &url.Values{
|
||||||
|
"fullname": []string{"true"},
|
||||||
|
"recursive": []string{"true"},
|
||||||
|
}, &categories)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := map[int]Category{}
|
||||||
|
|
||||||
|
for _, category := range categories.Categories {
|
||||||
|
result[category.Id] = category
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
26
internal/piwigo/time.go
Normal file
26
internal/piwigo/time.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package piwigo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TimeResult time.Time
|
||||||
|
|
||||||
|
func (c *TimeResult) UnmarshalJSON(b []byte) error {
|
||||||
|
value := strings.Trim(string(b), `"`) //get rid of "
|
||||||
|
if value == "" || value == "null" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
t, err := time.Parse("2006-01-02 15:04:05", value) //parse time
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*c = TimeResult(t) //set result using the pointer
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c TimeResult) MarshalJSON() ([]byte, error) {
|
||||||
|
return []byte(`"` + time.Time(c).Format(time.RFC3339) + `"`), nil
|
||||||
|
}
|
@ -15,6 +15,7 @@ type Category struct {
|
|||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ImagesCount int `json:"nb_images"`
|
ImagesCount int `json:"nb_images"`
|
||||||
|
Url string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetCategoriesListResponse struct {
|
type GetCategoriesListResponse struct {
|
||||||
@ -43,12 +44,13 @@ func (c *CategoriesListCommand) Execute(args []string) error {
|
|||||||
|
|
||||||
t := table.NewWriter()
|
t := table.NewWriter()
|
||||||
|
|
||||||
t.AppendHeader(table.Row{"Id", "Name", "Images"})
|
t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"})
|
||||||
for _, category := range resp.Categories {
|
for _, category := range resp.Categories {
|
||||||
t.AppendRow(table.Row{
|
t.AppendRow(table.Row{
|
||||||
category.Id,
|
category.Id,
|
||||||
category.Name,
|
category.Name,
|
||||||
category.ImagesCount,
|
category.ImagesCount,
|
||||||
|
category.Url,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,9 @@ type ImagesDetailsCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetImagesDetailsResponse struct {
|
type GetImagesDetailsResponse struct {
|
||||||
|
Categories []piwigo.Category `json:"categories"`
|
||||||
|
DateAvailable piwigo.TimeResult `json:"date_available"`
|
||||||
|
DateCreation piwigo.TimeResult `json:"date_creation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ImagesDetailsCommand) Execute(args []string) error {
|
func (c *ImagesDetailsCommand) Execute(args []string) error {
|
||||||
@ -30,5 +33,16 @@ func (c *ImagesDetailsCommand) Execute(args []string) error {
|
|||||||
}, &resp); err != nil {
|
}, &resp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
categories, err := p.Categories()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, category := range resp.Categories {
|
||||||
|
resp.Categories[i] = categories[category.Id]
|
||||||
|
}
|
||||||
|
|
||||||
|
piwigo.DumpResponse(resp)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func (c *MethodTryCommand) Execute(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var result map[string]interface{}
|
var result interface{}
|
||||||
params := &url.Values{}
|
params := &url.Values{}
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
r := strings.SplitN(arg, "=", 2)
|
r := strings.SplitN(arg, "=", 2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user