-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailTemplate.go
152 lines (130 loc) · 3.35 KB
/
emailTemplate.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"fmt"
toogoodtogo "github.com/simonmartyr/toogoodtogogo"
"log"
"time"
)
type PickupInfo struct {
StoreName string
ItemName string
PickupTime string
}
func ParseItems(items []*toogoodtogo.Item) *[]PickupInfo {
var processed []PickupInfo
for _, item := range items {
pickupItem := PickupInfo{
StoreName: item.Store.StoreName,
ItemName: item.Item.Name,
}
start, startErr := time.Parse(time.RFC3339, item.PickupInterval.Start)
end, endErr := time.Parse(time.RFC3339, item.PickupInterval.End)
timezone, timeZoneErr := time.LoadLocation(item.Store.StoreTimeZone)
if startErr != nil || endErr != nil || timeZoneErr != nil {
pickupItem.PickupTime = "unknown"
log.Println(fmt.Sprintf("Date time error for: %s", item.Item.Name))
} else {
pickupItem.PickupTime = fmt.Sprintf("from: %s until %s",
start.In(timezone).Format("15:04"),
end.In(timezone).Format("15:04"),
)
}
processed = append(processed, pickupItem)
}
return &processed
}
const emailTemplate = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Too Good To Go Availability</title>
<style>
/* Reset some default styles for better consistency */
body, p, table {
margin: 0;
padding: 0;
}
/* Add a background color and padding to the body */
body {
background-color: #f0f0f0;
padding: 20px;
}
/* Style the email container */
.email-container {
max-width: 600px;
margin: 0 auto;
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
/* Style the header */
h1 {
color: #333;
font-size: 24px;
margin-bottom: 20px;
}
/* Style the table */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 12px;
text-align: left;
}
/* Style table header */
th {
background-color: #333;
color: #fff;
}
/* Style table rows alternately */
tr:nth-child(even) {
background-color: #f2f2f2;
}
/* Style links */
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* Add spacing between elements */
.spacer {
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="email-container">
<h1>Too Good To Go Availability</h1>
<p>Dear User</p>
<p>The following Too Good To Go Items are available:</p>
<table>
<tr>
<th>Store Name</th>
<th>Item Name</th>
<th>Pickup Time</th>
</tr>
{{range .Items}}
<tr>
<td>{{.StoreName}}</td>
<td>{{.ItemName}}</td>
<td>{{.PickupTime}}</td>
</tr>
{{end}}
</table>
<div class="spacer"></div>
<p>Thank you.</p>
<p>Kind regards,<br>Raspberry Pi</p>
</div>
</body>
</html>
`