70 lines
2.3 KiB
Go
70 lines
2.3 KiB
Go
package main
|
||
|
||
import (
|
||
"fmt"
|
||
"log"
|
||
"time"
|
||
"week/moonshot"
|
||
"week/qywechat"
|
||
"week/tools"
|
||
|
||
"github.com/jasonlvhit/gocron"
|
||
)
|
||
|
||
var maxRetries = 0
|
||
var now = time.Now()
|
||
|
||
func main() {
|
||
fmt.Println("-----------------------------------------------------------------------------------------")
|
||
fmt.Println("-----------------------------------------------------------------------------------------")
|
||
log.Println(`
|
||
_____
|
||
_/ ____\______ ____ _____ _____ ____ __ _ _______ ____ ____
|
||
\ __\\_ __ \/ _ \ / \ \__ \ / _ \ \ \/ \/ /\__ \ / \ / ___\
|
||
| | | | \( <_> ) Y Y \ / __ \( <_> ) \ / / __ \| | \/ /_/ >
|
||
|__| |__| \____/|__|_| / (____ /\____/ \/\_/ (____ /___| /\___ /
|
||
\/ \/ \/ \//_____/ `)
|
||
fmt.Println("-----------------------------------------------------------------------------------------")
|
||
fmt.Println("-----------------------------------------------------------------------------------------")
|
||
if maxRetries < 3 {
|
||
for {
|
||
remainingTime := tools.RemainingTimeUntilNextFriday17()
|
||
if remainingTime <= 0 {
|
||
break // 当剩余时间小于等于0时跳出循环
|
||
}
|
||
fmt.Printf("距离执行定时任务还剩 %d小时 %d分钟 %d秒\n", int(remainingTime.Hours()), int(remainingTime.Minutes())%60, int(remainingTime.Seconds())%60)
|
||
time.Sleep(time.Minute * 10) // 等待30分钟钟,然后更新
|
||
}
|
||
// 定义任务,每周五的五点执行
|
||
gocron.Every(1).Friday().At("17:00").Do(job)
|
||
// 开始定时任务
|
||
<-gocron.Start()
|
||
|
||
} else {
|
||
log.Fatalln("最大重试次数已到达3,退出")
|
||
}
|
||
}
|
||
|
||
func job() {
|
||
nowDate := now.Format("2006-01-02 15:04:05") + " " + now.Weekday().String()
|
||
log.Printf("开始执行任务,当前时间是:%v", nowDate)
|
||
|
||
err := moonshot.CreateExcel()
|
||
if err != nil {
|
||
maxRetries++
|
||
log.Printf("执行失败,开始第%v次重试...", maxRetries)
|
||
log.Println("----------------------------------------------------------------------")
|
||
job()
|
||
|
||
}
|
||
repContent, err := moonshot.AiChat()
|
||
if err != nil {
|
||
maxRetries++
|
||
log.Printf("执行失败,开始第%v次重试...", maxRetries)
|
||
log.Println("----------------------------------------------------------------------")
|
||
job()
|
||
}
|
||
qywechat.Send(repContent)
|
||
|
||
}
|