summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-11-09 18:29:56 +0000
committerNick White <git@njw.name>2020-11-09 18:54:50 +0000
commita1de8862a091f9584220db40671a0d43346c4519 (patch)
tree9f146b4cc90e117250dafcf7bfd64f7edc3907a1 /cmd
parentfc6becf5ed98e9c0815532fd76639c15eb481ed1 (diff)
[rescribe] Local only combo tool basically now working. Testing is still minimal.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/rescribe/main.go55
1 files changed, 49 insertions, 6 deletions
diff --git a/cmd/rescribe/main.go b/cmd/rescribe/main.go
index e3781cb..c309367 100644
--- a/cmd/rescribe/main.go
+++ b/cmd/rescribe/main.go
@@ -10,6 +10,7 @@ package main
import (
"flag"
"fmt"
+ "io/ioutil"
"log"
"os"
"path/filepath"
@@ -88,7 +89,7 @@ func main() {
bookdir := flag.Arg(0)
var bookname string
- if flag.NArg() > 2 {
+ if flag.NArg() > 1 {
bookname = flag.Arg(1)
} else {
bookname = filepath.Base(bookdir)
@@ -102,22 +103,41 @@ func main() {
verboselog = log.New(n, "", 0)
}
+ tempdir, err := ioutil.TempDir("", "bookpipeline")
+ if err != nil {
+ log.Fatalln("Error setting up temporary directory:", err)
+ }
+
var conn Pipeliner
- // TODO: set tmpdir to a specific random thing for this run only
- conn = &bookpipeline.LocalConn{Logger: verboselog}
+ conn = &bookpipeline.LocalConn{Logger: verboselog, TempDir: tempdir}
conn.Log("Setting up session")
- err := conn.Init()
+ err = conn.Init()
if err != nil {
log.Fatalln("Error setting up connection:", err)
}
conn.Log("Finished setting up session")
- uploadbook(bookdir, bookname, *training, conn)
+ fmt.Printf("Copying book to pipeline\n")
+ err = uploadbook(bookdir, bookname, *training, conn)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ fmt.Printf("Processing book (this may take some time)\n")
processbook(*training, conn)
- // TODO: save book
+ fmt.Printf("Saving finished book to %s\n", bookname)
+ err = downloadbook(bookname, conn)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ err = os.RemoveAll(tempdir)
+ if err != nil {
+ log.Fatalf("Error removing temporary directory %s: %v", tempdir, err)
+ }
}
func uploadbook(dir string, name string, training string, conn Pipeliner) error {
@@ -142,6 +162,29 @@ func uploadbook(dir string, name string, training string, conn Pipeliner) error
return nil
}
+func downloadbook(name string, conn Pipeliner) error {
+ err := os.MkdirAll(name, 0755)
+ if err != nil {
+ log.Fatalln("Failed to create directory", name, err)
+ }
+
+ err = pipeline.DownloadBestPages(name, conn)
+ if err != nil {
+ return fmt.Errorf("Error downloading best pages: %v", err)
+ }
+
+ err = pipeline.DownloadPdfs(name, conn)
+ if err != nil {
+ return fmt.Errorf("Error downloading PDFs: %v", err)
+ }
+
+ err = pipeline.DownloadAnalyses(name, conn)
+ if err != nil {
+ return fmt.Errorf("Error downloading analyses: %v", err)
+ }
+
+ return nil
+}
func processbook(training string, conn Pipeliner) {
origPattern := regexp.MustCompile(`[0-9]{4}.jpg$`)