-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (44 loc) · 1011 Bytes
/
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
package main
import (
"fmt"
"log"
"net/http"
"github.com/kyokomi/emoji"
)
const downloadURL = "https://www.webfx.com/tools/emoji-cheat-sheet/"
type EmojiGroup struct {
Name string
Emojis []*Emoji
}
type Emoji struct {
Name string
Code string
}
func main() {
resp, err := http.Get(downloadURL)
if err != nil {
log.Fatalf("Failed to download %q: %v", downloadURL, err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatalf("Received bad HTTP status code from %q: %s", downloadURL, resp.Status)
}
emojis, err := parse(resp.Body)
if err != nil {
log.Fatalf("Failed to parse file: %v", err)
}
enrich(emojis)
err = generateCode(emojis)
if err != nil {
log.Fatalf("Failed to generate code: %v", err)
}
}
func enrich(groups []*EmojiGroup) {
codeMap := emoji.CodeMap()
for _, group := range groups {
for _, emoji := range group.Emojis {
key := fmt.Sprintf(":%s:", emoji.Name)
emoji.Code = codeMap[key] // may be empty string if not found
}
}
}