-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
56 lines (51 loc) · 1.18 KB
/
output.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
package utils
import (
"fmt"
"math"
"os"
"strings"
"time"
"gitlab.com/hartsfield/inboxer"
"google.golang.org/api/gmail/v1"
)
func WriteFile(msg *gmail.Message) error {
time, err := inboxer.ReceivedTime(msg.InternalDate)
if err != nil {
fmt.Println(err)
}
f, err := os.Create(fmt.Sprintf("./dump/%s-%s.txt", time.Format("2006-02-01"), msg.Id))
if err != nil {
fmt.Println(err)
return f.Close()
}
decoded, err := GetMsgBody(msg)
if err != nil {
fmt.Println(err)
return f.Close()
}
if _, err := f.WriteString(decoded + "\n"); err != nil {
fmt.Println(err)
return f.Close()
}
if _, err := f.WriteString("=============================================\n"); err != nil {
fmt.Println(err)
return f.Close()
}
if _, err := f.WriteString(msg.Snippet + "\n"); err != nil {
fmt.Println(err)
return f.Close()
}
return f.Close()
}
func ParseDateWithFormat(date string, layout ...string) (time.Time, error) {
if strings.HasSuffix(date, "Z") {
date = date[:len(date)-1] + "+00:00"
}
if len(layout) == 0 {
layout = []string{"2006-01-02T15:04:05-07:00"}
}
return time.Parse(layout[0], date)
}
func Round(value any) float64 {
return math.Round(value.(float64)*100) / 100
}