-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (46 loc) · 1.33 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
package main
import (
"time"
"log"
)
func main() {
progName := "slack_emoji_downloader"
log.SetPrefix(progName + ": ")
log.SetFlags(0)
http_client := httpClient()
log.Println("INFO: Get emojis list")
listEmojis, err := httpGetListEmojis(http_client)
if err != nil {
log.Fatal("FATAL: ", err)
}
howManyEmojis := 0
howManyAliases := 0
howManyNoslugify := 0
for emojiName, emojiUrl := range listEmojis {
emojiFullPath, err := fileDefinePath(emojiName, emojiUrl)
if err != nil {
log.Printf("INFO: Do not download %v because unable to slugify", emojiName)
howManyNoslugify++
continue
}
is_alias, _ := isAlias(emojiUrl)
if is_alias {
log.Printf("INFO: Do not download %v because it's an alias", emojiName)
howManyAliases++
continue
}
log.Printf("INFO: Download %v as %v", emojiUrl, emojiFullPath)
if downloadErr := httpDownloadEmoji(http_client, emojiFullPath, emojiUrl); downloadErr != nil {
log.Fatal("FATAL: ", downloadErr)
}
// Every 100 emojis let's sleep 2 seconds
howManyEmojis++
if howManyEmojis%100 == 0 {
time.Sleep(2 * time.Second)
}
}
log.Printf("------------------------------")
log.Printf("INFO: Success to download %v emojis", howManyEmojis)
log.Printf("INFO: Don't download %v aliases", howManyAliases)
log.Printf("INFO: Don't download %v slugify", howManyNoslugify)
}