-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
72 lines (63 loc) · 1.29 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"yuque_export/common"
"yuque_export/conf"
"yuque_export/flag"
)
func Init() {
// 解析命令行
flag.InitFlag()
// 解析配置文件
conf.ParseConfig(*flag.PathConfFile)
// 功能导航
if *flag.Version {
fmt.Println(conf.Version)
return
}
// 创建导出目录
err := os.MkdirAll(conf.GConf.FileDir, 0777)
if err != nil {
log.Fatal(err)
}
}
func main() {
// 初始化
Init()
// 得到所有bookID
bookIDs, err := common.GetAllBookIDs()
if err != nil {
fmt.Println(err)
return
}
// fmt.Println(bookIDs)
// return
// 得到所有docID
for _, bookID := range bookIDs {
docIDs, err := common.GetAllDocIDs(bookID)
if err != nil {
fmt.Printf("获取bookID=%d的文档id失败:%s\n", bookID, err.Error())
continue
}
// fmt.Println(docIDs)
// return
// 得到下载链接
for _, docID := range docIDs {
downloadUrl, err := common.API{}.GetDownloadLink(docID)
if err != nil {
fmt.Printf("获取docID=%d的下载链接失败:%s\n", docID, err.Error())
continue
}
// fmt.Println(downloadUrl)
// return
// 下载文件
err = common.API{}.DownloadDoc(downloadUrl)
if err != nil {
fmt.Printf("文件下载失败,错误:%s,url:%s\n", err, downloadUrl)
continue
}
}
}
}