Skip to content

Commit

Permalink
feat:timing
Browse files Browse the repository at this point in the history
  • Loading branch information
Winspain committed Dec 7, 2023
1 parent 39bdca3 commit 5ce46cb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lotteryGo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 使用官方 Golang 镜像作为基础镜像
FROM golang:latest

# 将当前目录的文件复制到容器的 /app 目录下
COPY . /app

# 设置工作目录
WORKDIR /app

# 编译 Go 应用
RUN go build -o main .

# 启动应用
CMD ["./main"]
5 changes: 4 additions & 1 deletion lotteryGo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module lotteryGo

go 1.21

require github.com/PuerkitoBio/goquery v1.8.1
require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/robfig/cron/v3 v3.0.1
)

require (
github.com/andybalholm/cascadia v1.3.1 // indirect
Expand Down
27 changes: 26 additions & 1 deletion lotteryGo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"encoding/json"
"fmt"
"github.com/PuerkitoBio/goquery"
"github.com/robfig/cron/v3"
"net/http"
"os"
"strings"
"time"
)

var prizeMap = map[string][]int{
Expand Down Expand Up @@ -217,7 +219,7 @@ func sendDingDingNotification(hookUrl string, drawPeriod, drawTime string, hitPr
return nil
}

func main() {
func run() {
latestNum, err := getLatestNumberBy500()
if err != nil {
fmt.Println("Error:", err)
Expand Down Expand Up @@ -250,3 +252,26 @@ func main() {
fmt.Println("Error:", err1)
}
}

func main() {
// 创建一个cron调度器
c := cron.New()

// 添加定时任务
_, err := c.AddFunc("0 */1 20-23 * 1,3,6", run)
if err != nil {
fmt.Println("添加定时任务失败:", err)
return
}

// 启动定时任务
c.Start()

// 运行一段时间,让定时任务执行
// 这里可以根据你的实际需求设置运行时间
// 这里只是一个示例,你可能需要让程序一直运行或者使用其他方法来阻止程序退出
for {
run()
time.Sleep(1 * time.Minute)
}
}

0 comments on commit 5ce46cb

Please sign in to comment.