-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
96 lines (86 loc) · 1.94 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"os"
"path/filepath"
"qnurye/Annotations_from_wxread/pkg/annotation"
"qnurye/Annotations_from_wxread/pkg/config"
"qnurye/Annotations_from_wxread/pkg/instructions"
"strconv"
"time"
)
func main() {
cfg, err := config.Load()
if err != nil {
panic(err)
}
c, err := os.ReadFile(cfg.SourceDirectory)
if err != nil {
panic(err)
}
seq := instructions.Parse(string(c))
var (
title string
source string
author string
chapter string
comment string
quotation string
date time.Time
)
for i, instruction := range seq {
switch instruction.Type {
case instructions.Source:
source = instruction.Value
case instructions.Author:
author = instruction.Value
case instructions.Chapter:
chapter = instruction.Value
case instructions.Comment:
comment = instruction.Value
case instructions.Quotation:
quotation = instruction.Value
case instructions.Date:
date, _ = time.Parse("time.RFC3339", instruction.Value)
}
if quotation != "" {
if cfg.AnnotationTitleConfigurable {
fmt.Printf(`#%d @ sequences:
Source: "%s" by %s on chapter "%s"
"%s"`, i+1, source, author, chapter, quotation)
if (date != time.Time{}) {
fmt.Printf(`annotated on %s`, date.Format("2006-01-02T15:04"))
}
if comment != "" {
fmt.Printf(`commented %s`, comment)
}
fmt.Print("\nTitle: ")
_, err := fmt.Scanln(&title)
if err != nil {
return
}
} else {
if comment != "" {
title = comment
} else {
title = chapter + "-" + strconv.Itoa(i)
}
}
o, err := filepath.Abs(cfg.OutputDirectory)
if err != nil {
return
}
annotation.Save(annotation.Annotation{
Source: source,
Title: title,
Date: date,
Author: author,
Quotation: quotation,
Chapter: chapter,
Comment: comment,
}, cfg.TemplateFilePath, o)
title, quotation, comment = "", "", ""
date = time.Time{}
}
}
}