-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (62 loc) · 1.58 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
73
74
75
76
77
78
79
80
81
82
package main
import (
"archive/zip"
"encoding/json"
"fmt"
fileUtil "github.com/danielnetop/notesnook-to-standardnotes/internal/file"
"github.com/danielnetop/notesnook-to-standardnotes/internal/notesnook"
"github.com/danielnetop/notesnook-to-standardnotes/internal/sn"
)
const tagsFileName = "0_tags.txt"
func main() {
backupFile, err := fileUtil.GetExportDataFile()
if err != nil {
fmt.Println(err.Error())
return
}
zf, err := fileUtil.ReadBackup(backupFile)
if err != nil {
fmt.Println(err.Error())
return
}
defer func(zf *zip.ReadCloser) {
err := zf.Close()
if err != nil {
fmt.Println(err.Error())
}
}(zf)
files, err := notesnook.ValidateBackupFiles(zf)
if err != nil {
fmt.Println(err.Error())
return
}
var nooks []notesnook.Nook
for _, file := range files {
processedNooks, err := notesnook.ProcessNotesnookExportData(file)
if err != nil {
fmt.Println(err.Error())
return
}
// This needs to be done this way because the note title and content might not be
// in the same notesnook backup file, so we need to fetch all data from backup
// and only after that we can process them into a sn file
nooks = append(nooks, processedNooks...)
}
err = sn.ProcessConversionAndSaveToFile(nooks)
if err != nil {
fmt.Println(err.Error())
return
}
if tags := sn.ConvertNotebooksToTags(); len(tags.Items) > 0 {
contentTags, err := json.Marshal(tags)
if err != nil {
fmt.Println(err.Error())
return
}
err = fileUtil.CreateFileFromContent(contentTags, tagsFileName)
if err != nil {
fmt.Println(err.Error())
return
}
}
}