mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-15 17:49:29 +02:00
Import result can report total and processed items
This commit is contained in:
parent
516de905bd
commit
ead323eaed
5 changed files with 14 additions and 7 deletions
|
@ -37,13 +37,15 @@ func (b DumpBackend) FromConfig(config *viper.Viper) models.Backend {
|
|||
|
||||
func (b DumpBackend) ImportListens(listens []models.Listen, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
result := models.ImportResult{
|
||||
Count: len(listens),
|
||||
TotalCount: len(listens),
|
||||
ImportCount: 0,
|
||||
LastTimestamp: oldestTimestamp,
|
||||
}
|
||||
for _, listen := range listens {
|
||||
if listen.ListenedAt.Unix() > result.LastTimestamp.Unix() {
|
||||
result.LastTimestamp = listen.ListenedAt
|
||||
}
|
||||
result.ImportCount += 1
|
||||
fmt.Printf("🎶 %v: \"%s\" by %s\n", listen.ListenedAt, listen.TrackName, listen.ArtistName())
|
||||
}
|
||||
return result, nil
|
||||
|
@ -51,13 +53,15 @@ func (b DumpBackend) ImportListens(listens []models.Listen, oldestTimestamp time
|
|||
|
||||
func (b DumpBackend) ImportLoves(loves []models.Love, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
result := models.ImportResult{
|
||||
Count: len(loves),
|
||||
TotalCount: len(loves),
|
||||
ImportCount: 0,
|
||||
LastTimestamp: oldestTimestamp,
|
||||
}
|
||||
for _, love := range loves {
|
||||
if love.Created.Unix() > result.LastTimestamp.Unix() {
|
||||
result.LastTimestamp = love.Created
|
||||
}
|
||||
result.ImportCount += 1
|
||||
fmt.Printf("❤️ %v: \"%s\" by %s\n", love.Created, love.TrackName, love.ArtistName())
|
||||
}
|
||||
return result, nil
|
||||
|
|
|
@ -58,7 +58,7 @@ func (b ScrobblerLogBackend) ExportListens(oldestTimestamp time.Time) ([]models.
|
|||
|
||||
func (b ScrobblerLogBackend) ImportListens(listens []models.Listen, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
result := models.ImportResult{
|
||||
Count: 0,
|
||||
TotalCount: len(listens),
|
||||
LastTimestamp: oldestTimestamp,
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,6 @@ func (b ScrobblerLogBackend) ImportListens(listens []models.Listen, oldestTimest
|
|||
}
|
||||
|
||||
result.LastTimestamp = lastTimestamp
|
||||
result.Count = len(listens)
|
||||
result.ImportCount = len(listens)
|
||||
return result, nil
|
||||
}
|
||||
|
|
|
@ -48,7 +48,8 @@ var listensCmd = &cobra.Command{
|
|||
cobra.CheckErr(err)
|
||||
result, err := importBackend.ImportListens(listens, timestamp)
|
||||
cobra.CheckErr(err)
|
||||
fmt.Printf("Imported %v listens (last timestamp %v)\n", result.Count, result.LastTimestamp)
|
||||
fmt.Printf("Imported %v of %v listens (last timestamp %v)\n",
|
||||
result.ImportCount, result.TotalCount, result.LastTimestamp)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,8 @@ var lovesCmd = &cobra.Command{
|
|||
cobra.CheckErr(err)
|
||||
result, err := importBackend.ImportLoves(loves, timestamp)
|
||||
cobra.CheckErr(err)
|
||||
fmt.Printf("Imported %v loves (last timestamp %v)\n", result.Count, result.LastTimestamp)
|
||||
fmt.Printf("Imported %v of %v loves (last timestamp %v)\n",
|
||||
result.ImportCount, result.TotalCount, result.LastTimestamp)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ type LovesImport interface {
|
|||
}
|
||||
|
||||
type ImportResult struct {
|
||||
Count int
|
||||
TotalCount int
|
||||
ImportCount int
|
||||
LastTimestamp time.Time
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue