-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemoji.go
88 lines (84 loc) · 2.25 KB
/
emoji.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
package main
import (
"fmt"
"net/http"
"regexp"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/gellel/emojipedia/arguments"
"github.com/gellel/emojipedia/emoji"
"github.com/gellel/emojipedia/slice"
"github.com/gellel/emojipedia/text"
)
func emojiMain(arguments *arguments.Arguments) {
e, err := emoji.Open(arguments.Get(0))
switch err == nil {
case true:
switch strings.ToUpper(arguments.Next().Get(0)) {
case A, ANCHOR:
fmt.Println(e.Anchor)
case C, CATEGORY:
fmt.Println(e.Category)
case CC, CODES:
e.Codes.Each(func(_ int, i interface{}) {
fmt.Println(i.(string))
})
case D, DESCRIPTION:
if len(e.Description) == 0 {
var (
resp, _ = http.Get("https://emojipedia.org/" + e.Name + "/")
document, _ = goquery.NewDocumentFromResponse(resp)
re = regexp.MustCompile(`\r?\n`)
paragraphs = &slice.Slice{}
)
document.Find("section.description > p").Each(func(_ int, selection *goquery.Selection) {
paragraphs.Append(re.ReplaceAllString(strings.TrimSpace(selection.Text()), " "))
})
e.Description = paragraphs.Join(" ")
emoji.Write(e)
}
fmt.Println(e.Description)
case E, EMOJI:
fmt.Println(text.Emojize(e.Unicode))
case H, HREF:
fmt.Println(e.Href)
case I, IMAGE:
fmt.Println(e.Image)
case K, KEYWORDS:
e.Keywords.Sort().Each(func(_ int, i interface{}) {
fmt.Println(i.(string))
})
case N, NUMBER:
fmt.Println(e.Number)
case S, SUBCATEGORY:
fmt.Println(e.Subcategory)
case T, TABLE:
var (
character = text.Emojize(e.Unicode)
category = e.Category
codes = e.Codes.Join(" ")
href = e.Href
keywords = e.Keywords.Sort().Join(" ")
name = e.Name
number = fmt.Sprintf("%v", e.Number)
subcategory = e.Subcategory
template = []string{
character,
category,
codes,
href,
keywords,
name,
number,
subcategory}
)
fmt.Fprintln(writer, "\t|category\t|codes\t|href\t|keywords\t|name\t|number\t|subcategory")
fmt.Fprintln(writer, strings.Join(template, "\t|"))
writer.Flush()
case "-U", UNICODE:
fmt.Println(e.Unicode)
}
default:
fmt.Println(fmt.Sprintf(errorChoiceNotFound, arguments.Get(0), "-ee", strings.ToLower(EMOJI)))
}
}