Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
closed #164 获取英文官网新闻,修复解析错误
Browse files Browse the repository at this point in the history
  • Loading branch information
axiangcoding committed Feb 25, 2023
1 parent 3b248b6 commit daebf41
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions api-system/internal/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ func addJob(c *cron.Cron) {
if _, err := c.AddFunc("@daily", RefreshUserTodayCount); err != nil {
logging.L().Fatal("add cron job RefreshUserTodayCount failed", logging.Error(err))
}
if _, err := c.AddFunc("@every 2m", CheckWTNewsUpdate); err != nil {
if _, err := c.AddFunc("@every 2m", func() {
CheckWTNewsUpdate("en")
CheckWTNewsUpdate("zh")
}); err != nil {
logging.L().Fatal("add cron job CheckWTNewsUpdate failed", logging.Error(err))
}
logging.L().Info("all cron job add success")
}

func CheckRoomLiving() {
if service.IsStopAllResponse() {
return
}
qcs, err := service.GetEnableCheckBiliRoomGroupConfig(true)
if err != nil {
logging.L().Warn("get group config checkbilibiliroom failed", logging.Error(err))
Expand Down Expand Up @@ -73,12 +79,15 @@ func RefreshUserTodayCount() {
}
}

func CheckWTNewsUpdate() {
if err := crawler.GetFirstPageNewsFromWTOfficial(func(news []table.GameNew) {
func CheckWTNewsUpdate(region string) {
if err := crawler.GetFirstPageNewsFromWTOfficial(region, func(news []table.GameNew) {
for _, item := range news {
found := service.MustFindGameNewByLink(item.Link)
if found == nil {
service.MustSaveGameNew(&item)
if service.IsStopAllResponse() {
return
}
// 向配置了的群发送消息
qcs, err := service.GetEnableCheckWTNew(true)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api-system/internal/data/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package display
import (
"bytes"
"github.com/axiangcoding/antonstar-bot/pkg/logging"
"html/template"
"text/template"
)

func parseTemplate(templateStr string, u any) string {
Expand Down
4 changes: 2 additions & 2 deletions api-system/pkg/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func GetProfileFromThunderskill(nick string, callback func(status int, skill *Th
return nil
}

func GetFirstPageNewsFromWTOfficial(callback func(news []table.GameNew)) error {
baseUrl := "https://warthunder.com/zh/news/"
func GetFirstPageNewsFromWTOfficial(region string, callback func(news []table.GameNew)) error {
baseUrl := fmt.Sprintf("https://warthunder.com/%s/news/", region)
c := colly.NewCollector(
colly.AllowedDomains("warthunder.com"),
colly.MaxDepth(1),
Expand Down
2 changes: 1 addition & 1 deletion api-system/pkg/crawler/crawler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestGetProfileFromThunderskill(t *testing.T) {
}

func TestGetFirstPageNewsFromWTOfficial(t *testing.T) {
if err := GetFirstPageNewsFromWTOfficial(func(news []table2.GameNew) {
if err := GetFirstPageNewsFromWTOfficial("en", func(news []table2.GameNew) {
fmt.Println(len(news))
for _, i := range news {
fmt.Println(i)
Expand Down

0 comments on commit daebf41

Please sign in to comment.