aboutsummaryrefslogtreecommitdiffstats
path: root/skate/cmd/skate-conv
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-05-25 00:32:28 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-05-25 00:32:28 +0200
commit5e082f6c0154887011c47f03c80c48352e8cdc77 (patch)
treefc347c7010ae40dae9d4949e5fe0a041489768eb /skate/cmd/skate-conv
parent36b08fbf951e75eb034f06a30938d5ebaedba354 (diff)
downloadrefcat-5e082f6c0154887011c47f03c80c48352e8cdc77.tar.gz
refcat-5e082f6c0154887011c47f03c80c48352e8cdc77.zip
ol editions converter
Diffstat (limited to 'skate/cmd/skate-conv')
-rw-r--r--skate/cmd/skate-conv/main.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/skate/cmd/skate-conv/main.go b/skate/cmd/skate-conv/main.go
index 27f09e2..d48c913 100644
--- a/skate/cmd/skate-conv/main.go
+++ b/skate/cmd/skate-conv/main.go
@@ -21,7 +21,7 @@ import (
var (
numWorkers = flag.Int("w", runtime.NumCPU(), "number of workers")
batchSize = flag.Int("b", 100000, "batch size")
- fromFormat = flag.String("f", "ref", "import schema: ref, rg, ol")
+ fromFormat = flag.String("f", "ref", "import schema: ref, rg, ol, oled")
f func([]byte) ([]byte, error) // our converter function
)
@@ -35,6 +35,8 @@ func main() {
f = rgSitemapToRelease
case "ol":
f = openLibraryToRelease
+ case "oled":
+ f = openLibraryEditionToRelease
default:
log.Fatalf("unsupported input schema: %v", *fromFormat)
}
@@ -104,3 +106,21 @@ func openLibraryToRelease(p []byte) ([]byte, error) {
release.Extra.Skate.Status = "ol"
return skate.JsonMarshalNewline(release)
}
+
+// openLibraryEditionToRelease converts an Open Library edition item to a
+// release.
+func openLibraryEditionToRelease(p []byte) ([]byte, error) {
+ var (
+ w skate.OpenLibraryEdition
+ release *skate.Release
+ err error
+ )
+ if err = json.Unmarshal(p, &w); err != nil {
+ return nil, err
+ }
+ if release, err = skate.OpenLibraryEditionToRelease(&w); err != nil {
+ return nil, err
+ }
+ release.Extra.Skate.Status = "oled"
+ return skate.JsonMarshalNewline(release)
+}