mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
docs: update wcl, select match time
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
|||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "wcl",
|
Use: "wcl",
|
||||||
Short: "Monitor FIFA World Cup Live",
|
Short: "Monitor FIFA World Cup Live",
|
||||||
Version: "2022.12.01.2236",
|
Version: "2022.12.03.0018",
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
log.Logger = zerolog.New(
|
log.Logger = zerolog.New(
|
||||||
zerolog.ConsoleWriter{NoColor: false, Out: os.Stderr},
|
zerolog.ConsoleWriter{NoColor: false, Out: os.Stderr},
|
||||||
|
|||||||
+33
-20
@@ -154,32 +154,49 @@ func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
|
|||||||
utcTimeStr := utcTime.Format("15:04:05")
|
utcTimeStr := utcTime.Format("15:04:05")
|
||||||
fileName := filepath.Join(
|
fileName := filepath.Join(
|
||||||
wc.resultDir, "screenshot", utcTimeStr)
|
wc.resultDir, "screenshot", utcTimeStr)
|
||||||
ocrTexts, err := wc.driver.GetTextsByOCR(uixt.WithScreenShot(fileName))
|
ocrTexts, err := wc.driver.GetTextsByOCR(
|
||||||
|
uixt.WithScreenShot(fileName),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("get ocr texts failed")
|
log.Error().Err(err).Msg("get ocr texts failed")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var liveTimeSeconds int
|
// filter ocr texts with time format
|
||||||
|
secondsMap := map[string]int{}
|
||||||
|
var secondsTexts []string
|
||||||
for _, ocrText := range ocrTexts {
|
for _, ocrText := range ocrTexts {
|
||||||
seconds, err := convertTimeToSeconds(ocrText.Text)
|
seconds, err := convertTimeToSeconds(ocrText.Text)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
liveTimeSeconds = seconds
|
secondsTexts = append(secondsTexts, ocrText.Text)
|
||||||
line := fmt.Sprintf("%s\t%d\t%s\t%d\n",
|
secondsMap[ocrText.Text] = seconds
|
||||||
utcTimeStr, utcTime.Unix(), ocrText.Text, liveTimeSeconds)
|
|
||||||
log.Info().Str("utcTime", utcTimeStr).Str("liveTime", ocrText.Text).Msg("log live time")
|
|
||||||
if _, err := wc.file.WriteString(line); err != nil {
|
|
||||||
log.Error().Err(err).Str("line", line).Msg("write timeseries failed")
|
|
||||||
}
|
|
||||||
wc.Timelines = append(wc.Timelines, timeLog{
|
|
||||||
UTCTimeStr: utcTimeStr,
|
|
||||||
UTCTime: utcTime.Unix(),
|
|
||||||
LiveTime: ocrText.Text,
|
|
||||||
LiveTimeSeconds: liveTimeSeconds,
|
|
||||||
})
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var secondsText string
|
||||||
|
if len(secondsTexts) == 1 {
|
||||||
|
secondsText = secondsTexts[0]
|
||||||
|
} else if len(secondsTexts) >= 2 {
|
||||||
|
// select the second, the first maybe mobile system time
|
||||||
|
secondsText = secondsTexts[1]
|
||||||
|
} else {
|
||||||
|
log.Warn().Msg("no time text found")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
liveTimeSeconds := secondsMap[secondsText]
|
||||||
|
line := fmt.Sprintf("%s\t%d\t%s\t%d\n",
|
||||||
|
utcTimeStr, utcTime.Unix(), secondsText, liveTimeSeconds)
|
||||||
|
log.Info().Str("utcTime", utcTimeStr).Str("liveTime", secondsText).Msg("log live time")
|
||||||
|
if _, err := wc.file.WriteString(line); err != nil {
|
||||||
|
log.Error().Err(err).Str("line", line).Msg("write timeseries failed")
|
||||||
|
}
|
||||||
|
wc.Timelines = append(wc.Timelines, timeLog{
|
||||||
|
UTCTimeStr: utcTimeStr,
|
||||||
|
UTCTime: utcTime.Unix(),
|
||||||
|
LiveTime: secondsText,
|
||||||
|
LiveTimeSeconds: liveTimeSeconds,
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,10 +222,6 @@ func (wc *WorldCupLive) EnterLive(bundleID string) error {
|
|||||||
_ = wc.driver.TapAbsXY(points[1].X, points[1].Y)
|
_ = wc.driver.TapAbsXY(points[1].X, points[1].Y)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = wc.driver.SwipeRelative(0.5, 0.1, 0.8, 0.1); err != nil {
|
|
||||||
log.Error().Err(err).Msg("swipe failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 进入世界杯 tab
|
// 进入世界杯 tab
|
||||||
if err = wc.driver.TapByOCR("世界杯"); err != nil {
|
if err = wc.driver.TapByOCR("世界杯"); err != nil {
|
||||||
log.Error().Err(err).Msg("enter 直播中 failed")
|
log.Error().Err(err).Msg("enter 直播中 failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user