forked from Vanessa219/Vanessa219
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
112 lines (102 loc) ยท 3.36 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
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
package main
import (
"bytes"
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
"github.com/88250/gulu"
"github.com/parnurzeal/gorequest"
)
var logger = gulu.Log.NewLogger(os.Stdout)
const (
githubUserName = "Vanessa219"
liandiUserName = "Vanessa"
)
func main() {
result := map[string]interface{}{}
response, data, errors := gorequest.New().TLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
Get("https://ld246.com/api/v2/user/"+liandiUserName+"/events?size=8").Timeout(7*time.Second).
Set("User-Agent", "Profile Bot; +https://github.com/"+githubUserName+"/"+githubUserName).EndStruct(&result)
if nil != errors || http.StatusOK != response.StatusCode {
logger.Fatalf("fetch events failed: %+v, %s", errors, data)
}
if 0 != result["code"].(float64) {
logger.Fatalf("fetch events failed: %s", data)
}
buf := &bytes.Buffer{}
buf.WriteString("\n\n")
cstSh, _ := time.LoadLocation("Asia/Shanghai")
updated := time.Now().In(cstSh).Format("2006-01-02 15:04:05")
buf.WriteString("### ๆๅจ[้พๆปด](https://ld246.com)็่ฟๆๅจๆ\n\nโญ๏ธ Star [ไธชไบบไธป้กต](https://github.com/" + githubUserName + "/" + githubUserName + ") ๅไผ่ชๅจๆดๆฐ๏ผๆ่ฟๆดๆฐๆถ้ด๏ผ`" + updated + "`\n\n๐ ๅธๅญ ๐ฌ ่ฏ่ฎบ ๐ฃ ๅๅธ ๐ ๆธ
ๆ ๐จโ๐ป ็จๆท ๐ท๏ธ ๆ ็ญพ โญ๏ธ ๅ
ณๆณจ ๐ ่ตๅ ๐ ๆ่ฐข ๐ฐ ๆ่ต ๐ ๆถ่\n\n")
for _, event := range result["data"].([]interface{}) {
evt := event.(map[string]interface{})
operation := evt["operation"].(string)
title := evt["title"].(string)
typ := evt["type"].(string)
var emoji string
switch typ {
case "article":
emoji = "๐"
case "comment":
emoji = "๐ฌ"
case "comment2":
emoji = "๐ฃ"
case "breezemoon":
emoji = "๐"
title = operation
case "vote-article":
emoji = "๐๐"
case "vote-comment":
emoji = "๐๐ฌ"
case "vote-comment2":
emoji = "๐๐ฃ"
case "vote-breezemoon":
emoji = "๐๐"
title = operation
case "reward-article":
emoji = "๐ฐ๐"
case "thank-article":
emoji = "๐๐"
case "thank-comment":
emoji = "๐๐ฌ"
case "accept-comment":
emoji = "โ
๐ฌ"
case "thank-comment2":
emoji = "๐๐ฃ"
case "thank-breezemoon":
emoji = "๐๐"
title = operation
case "follow-user":
emoji = "โญ๏ธ๐จโ๐ป"
case "follow-tag":
emoji = "โญ๏ธ๐ท๏ธ"
case "collect-article":
emoji = "๐๐"
}
url := evt["url"].(string)
content := evt["content"].(string)
buf.WriteString("* " + emoji + " [" + title + "](" + url + ")\n\n" + " > " + content + "\n")
}
buf.WriteString("\n\n")
fmt.Println(buf.String())
readme, err := ioutil.ReadFile("README.md")
if nil != err {
logger.Fatalf("read README.md failed: %s", data)
}
startFlag := []byte("<!--events start -->")
beforeStart := readme[:bytes.Index(readme, startFlag)+len(startFlag)]
newBeforeStart := make([]byte, len(beforeStart))
copy(newBeforeStart, beforeStart)
endFlag := []byte("<!--events end -->")
afterEnd := readme[bytes.Index(readme, endFlag):]
newAfterEnd := make([]byte, len(afterEnd))
copy(newAfterEnd, afterEnd)
newReadme := append(newBeforeStart, buf.Bytes()...)
newReadme = append(newReadme, newAfterEnd...)
if err := ioutil.WriteFile("README.md", newReadme, 0644); nil != err {
logger.Fatalf("write README.md failed: %s", data)
}
}