Skip to content

Commit

Permalink
test keep session
Browse files Browse the repository at this point in the history
  • Loading branch information
zJiaJun committed Mar 26, 2024
1 parent a853466 commit f440c2c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ func main() {
if trade {
e.RunTradeData()
}
e.KeepSession()
logger.Info("Main engine finish")
}
9 changes: 7 additions & 2 deletions engine/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"gitub.com/zJiajun/warmane/config"
"gitub.com/zJiajun/warmane/constant"
"gitub.com/zJiajun/warmane/logger"
"gitub.com/zJiajun/warmane/model"
)

func (e *Engine) RunDailyPoints() {
Expand Down Expand Up @@ -50,7 +49,13 @@ func (e *Engine) collect(account config.Account) error {
c := e.getScraper(name).CloneCollector()
e.getScraper(name).SetRequestHeaders(c)
e.getScraper(name).DecodeResponse(c)
var bodyMsg model.BodyMsg
var bodyMsg struct {
Messages struct {
Success []string `json:"success"`
Error []string `json:"error"`
}
Points []float64 `json:"points"`
}
c.OnResponse(func(response *colly.Response) {
bodyText := string(response.Body)
err := json.Unmarshal(response.Body, &bodyMsg)
Expand Down
21 changes: 19 additions & 2 deletions engine/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@ import (
"gitub.com/zJiajun/warmane/constant"
"gitub.com/zJiajun/warmane/errors"
"gitub.com/zJiajun/warmane/logger"
"gitub.com/zJiajun/warmane/model"
"os"
"strings"
"time"
)

func (e *Engine) KeepSession() {
t := time.NewTicker(11 * time.Minute)
for {
select {
case <-t.C:
if err := e.login(e.config.Accounts[0]); err != nil {
logger.Errorf("账号[%s]登录错误, 原因: %v", e.config.Accounts[0].Username, err)
}
}
}
}

func (e *Engine) login(account config.Account) error {
name := account.Username
cookiesFile := constant.CookieFileName(name)
Expand Down Expand Up @@ -43,7 +55,12 @@ func (e *Engine) login(account config.Account) error {
e.getScraper(name).SetRequestHeaders(c)
e.getScraper(name).DecodeResponse(c)
var bodyErr error
var bodyMsg model.BodyMsg
var bodyMsg struct {
Messages struct {
Success []string `json:"success"`
Error []string `json:"error"`
}
}
c.OnResponse(func(response *colly.Response) {
bodyText := string(response.Body)
bodyErr = json.Unmarshal(response.Body, &bodyMsg)
Expand Down
4 changes: 3 additions & 1 deletion engine/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func (e *Engine) trade(account config.Account) error {
c := e.getScraper(name).CloneCollector()
e.getScraper(name).SetRequestHeaders(c)
e.getScraper(name).DecodeResponse(c)
var tradeResp model.TradeResp
var tradeResp struct {
Content []string `json:"content"`
}
c.OnResponse(func(response *colly.Response) {
respBody := response.Body
err := json.Unmarshal(respBody, &tradeResp)
Expand Down
9 changes: 0 additions & 9 deletions model/bodymsg.go

This file was deleted.

4 changes: 0 additions & 4 deletions model/trade.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package model

type TradeResp struct {
Content []string `json:"content"`
}

type TradeInfo struct {
Name string //角色名称
ArmoryUrl string //角色详情地址
Expand Down

0 comments on commit f440c2c

Please sign in to comment.