Added CSV export
This commit is contained in:
parent
093385b153
commit
a9ba01e610
43
pages/export/CSV.go
Normal file
43
pages/export/CSV.go
Normal file
@ -0,0 +1,43 @@
|
||||
package export
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
)
|
||||
|
||||
// CSV renders the anime list items in plain text format.
|
||||
func CSV(ctx aero.Context) error {
|
||||
animeList, err := getAnimeList(ctx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buffer := bytes.Buffer{}
|
||||
|
||||
// Header
|
||||
buffer.WriteString("Title,Status,Episodes,Overall,Story,Visuals,Soundtrack,Rewatched\n")
|
||||
|
||||
// List items
|
||||
for _, item := range animeList.Items {
|
||||
anime := item.Anime()
|
||||
fmt.Fprintf(
|
||||
&buffer,
|
||||
"%s,%s,%d,%.1f,%.1f,%.1f,%.1f,%d\n",
|
||||
anime.Title.Canonical,
|
||||
item.Status,
|
||||
item.Episodes,
|
||||
item.Rating.Overall,
|
||||
item.Rating.Story,
|
||||
item.Rating.Visuals,
|
||||
item.Rating.Soundtrack,
|
||||
item.RewatchCount,
|
||||
)
|
||||
}
|
||||
|
||||
ctx.Response().SetHeader("Content-Type", "text/csv")
|
||||
ctx.Response().SetHeader("Content-Disposition", "attachment; filename=\"anime-list.csv\"")
|
||||
return ctx.String(buffer.String())
|
||||
}
|
@ -7,8 +7,8 @@ import (
|
||||
"github.com/aerogo/aero"
|
||||
)
|
||||
|
||||
// Text renders the anime list items in plain text format.
|
||||
func Text(ctx aero.Context) error {
|
||||
// TXT renders the anime list items in plain text format.
|
||||
func TXT(ctx aero.Context) error {
|
||||
animeList, err := getAnimeList(ctx)
|
||||
|
||||
if err != nil {
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
// Register registers the page routes.
|
||||
func Register(app *aero.Application) {
|
||||
app.Get("/user/:nick/animelist/export/text", export.Text)
|
||||
app.Get("/user/:nick/animelist/export/csv", export.CSV)
|
||||
app.Get("/user/:nick/animelist/export/txt", export.TXT)
|
||||
app.Get("/user/:nick/animelist/export/json", export.JSON)
|
||||
}
|
||||
|
@ -65,6 +65,12 @@ component SettingsAccounts(user *arn.User)
|
||||
Icon("upload")
|
||||
span Export
|
||||
|
||||
.widget-section
|
||||
label CSV:
|
||||
a.button(href=user.Link() + "/animelist/export/csv", target="_blank")
|
||||
Icon("upload")
|
||||
span Export as CSV
|
||||
|
||||
.widget-section
|
||||
label JSON:
|
||||
a.button(href=user.Link() + "/animelist/export/json", target="_blank")
|
||||
@ -73,6 +79,6 @@ component SettingsAccounts(user *arn.User)
|
||||
|
||||
.widget-section
|
||||
label TXT:
|
||||
a.button(href=user.Link() + "/animelist/export/text", target="_blank")
|
||||
a.button(href=user.Link() + "/animelist/export/txt", target="_blank")
|
||||
Icon("upload")
|
||||
span Export as TXT
|
||||
|
Loading…
Reference in New Issue
Block a user