-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (44 loc) · 1.11 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
package main
import (
"bytes"
"encoding/json"
"fmt"
"github.com/TRPGEngine/DailyReporter/report"
_ "github.com/joho/godotenv/autoload"
"io/ioutil"
"net/http"
"os"
"strings"
)
func sendReport(targetUrl string, reportText string) {
data := make(map[string]string)
data["msg"] = reportText
bytesData, err := json.Marshal(data)
if err != nil {
panic(err)
}
resp, err := http.Post(targetUrl, "application/json", bytes.NewReader(bytesData))
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}
func main() {
botUrl := os.Getenv("BOT_URL")
if botUrl == "" {
panic("缺少机器人Url")
}
apikey := os.Getenv("WAKATIME_APIKEY")
wakaReport := report.GetWakatimeCodingReport(apikey)
username := os.Getenv("USERNAME")
githubReport := report.GetGithubActiveReport(username)
weatherReport := report.GetWeatherReport()
trpgReport := report.GetTRPGEngineReport()
reportText := strings.Join([]string{wakaReport, githubReport, weatherReport, trpgReport}, "---------\n")
sendReport(botUrl, reportText)
}