-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCvtGdocToDbgTxt.go
95 lines (78 loc) · 2.14 KB
/
CvtGdocToDbgTxt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// program that converts gdoc doc to a text doc
// author prr
// created 12/2021
//
// 9/12/21
// split into two packages
//
// CvtGdocToTxtv1.go from rd_Gdocv4.go
// v1 move test to Gdoc
//
package main
import (
"fmt"
"os"
"strings"
gdocApi "google/gdoc/gdocApi"
gdocDbg "google/gdoc/gdocDbgTxt"
)
func main() {
var gd gdocApi.GdocApiStruct
// intialise
baseFolder := "output"
baseFolderSlash := baseFolder + "/"
numArgs := len(os.Args)
cmd := os.Args[0]
switch numArgs {
case 1:
fmt.Println("error - no comand line arguments!")
fmt.Printf("%s usage is:\n %s docId folder\n", cmd[2:], cmd)
os.Exit(1)
case 2:
// doc id
case 3:
// output folder
default:
fmt.Println("error - too many arguments!")
fmt.Printf("%s usage is:\n %s folder docId\n", cmd[2:], cmd)
os.Exit(1)
}
docId := os.Args[1]
err := gd.InitGdocApi()
if err != nil {
fmt.Printf("error - InitGdocApi: %v!", err)
os.Exit(1)
}
srv := gd.Svc
outfilPath:= ""
switch {
case numArgs == 2:
outfilPath = baseFolder
case os.Args[2] == baseFolder:
outfilPath = os.Args[2]
case strings.Index(os.Args[2], baseFolderSlash)< 0:
outfilPath = baseFolderSlash + os.Args[2]
case strings.Index(os.Args[2], baseFolderSlash) == 0:
outfilPath = os.Args[2]
case os.Args[2] == "":
outfilPath = baseFolder
default:
fmt.Printf("no valid input folder: %s", os.Args[2])
os.Exit(1)
}
// docId := "1pdI_GFPR--q88V3WNKogcPfqa5VFOpzDZASo4alCKrE"
doc, err := srv.Documents.Get(docId).Do()
if err != nil {
fmt.Println("Unable to retrieve data from document: ", err)
os.Exit(1)
}
fmt.Printf("*************** Gdoc Debug ************\n")
fmt.Printf("The title of the doc is: %s\n", doc.Title)
fmt.Printf("Destination folder: %s\n", outfilPath)
err = gdocDbg.CvtGdocToDbgTxt(outfilPath, doc, nil)
if err != nil {
fmt.Println("error main -- cannot convert gdoc file: ", err)
os.Exit(1)
}
fmt.Println("Success!")
}