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"
|
"github.com/aerogo/aero"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Text renders the anime list items in plain text format.
|
// TXT renders the anime list items in plain text format.
|
||||||
func Text(ctx aero.Context) error {
|
func TXT(ctx aero.Context) error {
|
||||||
animeList, err := getAnimeList(ctx)
|
animeList, err := getAnimeList(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
// Register registers the page routes.
|
// Register registers the page routes.
|
||||||
func Register(app *aero.Application) {
|
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)
|
app.Get("/user/:nick/animelist/export/json", export.JSON)
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,12 @@ component SettingsAccounts(user *arn.User)
|
|||||||
h3.widget-title
|
h3.widget-title
|
||||||
Icon("upload")
|
Icon("upload")
|
||||||
span Export
|
span Export
|
||||||
|
|
||||||
|
.widget-section
|
||||||
|
label CSV:
|
||||||
|
a.button(href=user.Link() + "/animelist/export/csv", target="_blank")
|
||||||
|
Icon("upload")
|
||||||
|
span Export as CSV
|
||||||
|
|
||||||
.widget-section
|
.widget-section
|
||||||
label JSON:
|
label JSON:
|
||||||
@ -73,6 +79,6 @@ component SettingsAccounts(user *arn.User)
|
|||||||
|
|
||||||
.widget-section
|
.widget-section
|
||||||
label TXT:
|
label TXT:
|
||||||
a.button(href=user.Link() + "/animelist/export/text", target="_blank")
|
a.button(href=user.Link() + "/animelist/export/txt", target="_blank")
|
||||||
Icon("upload")
|
Icon("upload")
|
||||||
span Export as TXT
|
span Export as TXT
|
||||||
|
Loading…
Reference in New Issue
Block a user