使用火狐进行学习
This commit is contained in:
parent
0b956948a1
commit
a80185e2f5
34
lib/core.go
34
lib/core.go
|
@ -10,8 +10,6 @@ import (
|
|||
"image/jpeg"
|
||||
"image/png"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
qrcodeTerminal "github.com/Baozisoftware/qrcode-terminal-go"
|
||||
|
@ -51,20 +49,20 @@ func (c *Core) Init() {
|
|||
return
|
||||
}
|
||||
c.pw = pwt
|
||||
browser, err := pwt.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
|
||||
browser, err := pwt.Firefox.Launch(playwright.BrowserTypeLaunchOptions{
|
||||
Args: []string{
|
||||
"--disable-extensions",
|
||||
"--disable-gpu",
|
||||
// "--disable-gpu",
|
||||
"--start-maximized",
|
||||
"--no-sandbox",
|
||||
"--window-size=500,450",
|
||||
"--mute-audio",
|
||||
// "--mute-audio",
|
||||
"--window-position=0,0",
|
||||
"--ignore-certificate-errors",
|
||||
"--ignore-ssl-errors",
|
||||
"--disable-features=RendererCodeIntegrity",
|
||||
"--disable-blink-features",
|
||||
"--disable-blink-features=AutomationControlled",
|
||||
// "--ignore-ssl-errors",
|
||||
// "--disable-features=RendererCodeIntegrity",
|
||||
// "--disable-blink-features",
|
||||
// "--disable-blink-features=AutomationControlled",
|
||||
},
|
||||
Channel: nil,
|
||||
ChromiumSandbox: nil,
|
||||
|
@ -87,6 +85,7 @@ func (c *Core) Init() {
|
|||
c.browser = browser
|
||||
|
||||
context, err := c.browser.NewContext()
|
||||
c.browser.NewContext()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -137,14 +136,14 @@ func (c *Core) Login() ([]Cookie, error) {
|
|||
return nil, err
|
||||
}
|
||||
log.Infoln("[core] ", "正在等待二维码加载")
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
c.Push("text", "正在加载二维码")
|
||||
//if runtime.GOOS == "windows" {
|
||||
time.Sleep(3 * time.Second)
|
||||
} else {
|
||||
_, _ = page.WaitForSelector(`#app > div > div.login_content > div > div.login_qrcode `, playwright.PageWaitForSelectorOptions{
|
||||
State: playwright.WaitForSelectorStateVisible,
|
||||
})
|
||||
}
|
||||
//} else {
|
||||
// _, _ = page.WaitForSelector(`#app > div > div.login_content > div > div.login_qrcode `, playwright.PageWaitForSelectorOptions{
|
||||
// State: playwright.WaitForSelectorStateVisible,
|
||||
// })
|
||||
//}
|
||||
|
||||
_, err = page.Evaluate(`let h = document.body.scrollWidth/2;document.documentElement.scrollTop=h;`)
|
||||
|
||||
|
@ -176,9 +175,10 @@ func (c *Core) Login() ([]Cookie, error) {
|
|||
|
||||
c.Push("markdown", fmt.Sprintf(" \n>点开查看登录二维码\n>请在五分钟内完成扫码", "data:image/png;base64,"+base64.StdEncoding.EncodeToString(buffer.Bytes())))
|
||||
c.Push("image", base64.StdEncoding.EncodeToString(buffer.Bytes()))
|
||||
os.WriteFile("screen.png", buffer.Bytes(), 0666)
|
||||
//os.WriteFile("screen.png", buffer.Bytes(), 0666)
|
||||
matrix := GetPaymentStr(bytes.NewReader(buffer.Bytes()))
|
||||
log.Debugln("已获取到二维码内容:" + matrix.GetText())
|
||||
|
||||
c.Push("text", "https://techxuexi.js.org/jump/techxuexi-20211023.html?"+matrix.GetText())
|
||||
c.Push("text", matrix.GetText())
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ func (c *Core) LearnArticle(cookies []Cookie) {
|
|||
c.Push("text", "正在学习文章:"+links[n].Title)
|
||||
log.Infoln("文章发布时间:" + links[n].PublishTime)
|
||||
log.Infoln("文章学习链接:" + links[n].Url)
|
||||
learnTime := 70 + rand.Intn(30) + 10
|
||||
learnTime := 60 + rand.Intn(15) + 3
|
||||
for i := 0; i < learnTime; i++ {
|
||||
if c.IsQuit() {
|
||||
return
|
||||
|
@ -244,7 +244,7 @@ func (c *Core) LearnVideo(cookies []Cookie) {
|
|||
c.Push("text", "正在观看视频:"+links[n].Title)
|
||||
log.Infoln("视频发布时间:" + links[n].PublishTime)
|
||||
log.Infoln("视频学习链接:" + links[n].Url)
|
||||
learnTime := 70 + rand.Intn(30) + 10
|
||||
learnTime := 60 + rand.Intn(10) + 5
|
||||
for i := 0; i < learnTime; i++ {
|
||||
if c.IsQuit() {
|
||||
return
|
||||
|
|
5
main.go
5
main.go
|
@ -17,7 +17,10 @@ import (
|
|||
"github.com/huoxue1/study_xxqg/push"
|
||||
)
|
||||
|
||||
var VERSION = "unknown"
|
||||
|
||||
func init() {
|
||||
|
||||
config = lib.GetConfig()
|
||||
logFormatter := &easy.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
|
@ -115,7 +118,7 @@ func do() {
|
|||
log.Infoln("已选择用户: ", users[i-1].Nick)
|
||||
}
|
||||
|
||||
core.LearnArticle(cookies)
|
||||
//core.LearnArticle(cookies)
|
||||
core.LearnVideo(cookies)
|
||||
if config.Model == 2 {
|
||||
core.RespondDaily(cookies, "daily")
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
git pull
|
||||
go mod tidy
|
||||
go build ./
|
||||
nohup ./study_xxqg > study_xxqg.log 2>&1 & echo $!>pid.pid
|
|
@ -0,0 +1,56 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
type Bar struct {
|
||||
percent int64 //百分比
|
||||
cur int64 //当前进度位置
|
||||
total int64 //总进度
|
||||
rate string //进度条
|
||||
graph string //显示符号
|
||||
io.Reader
|
||||
}
|
||||
|
||||
func (bar *Bar) Read(p []byte) (n int, err error) {
|
||||
n, err = bar.Reader.Read(p)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
bar.Play(bar.cur + int64(n))
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (bar *Bar) NewOption(start, total int64, reader io.Reader) {
|
||||
bar.Reader = reader
|
||||
bar.cur = start
|
||||
bar.total = total
|
||||
if bar.graph == "" {
|
||||
bar.graph = "█"
|
||||
}
|
||||
bar.percent = bar.getPercent()
|
||||
for i := 0; i < int(bar.percent); i += 2 {
|
||||
bar.rate += bar.graph //初始化进度条位置
|
||||
}
|
||||
}
|
||||
|
||||
func (bar *Bar) getPercent() int64 {
|
||||
return int64(float32(bar.cur) / float32(bar.total) * 100)
|
||||
}
|
||||
|
||||
func (bar *Bar) NewOptionWithGraph(start, total int64, reader io.Reader, graph string) {
|
||||
bar.graph = graph
|
||||
bar.NewOption(start, total, reader)
|
||||
}
|
||||
|
||||
func (bar *Bar) Play(cur int64) {
|
||||
bar.cur = cur
|
||||
last := bar.percent
|
||||
bar.percent = bar.getPercent()
|
||||
if bar.percent != last && bar.percent%2 == 0 {
|
||||
bar.rate += bar.graph
|
||||
}
|
||||
fmt.Printf("\r[%-50s]%3d%% %8d/%d", bar.rate, bar.percent, bar.cur, bar.total)
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/guonaihong/gout"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func SelfUpdate(github string, baseVersion string) {
|
||||
if github == "" {
|
||||
github = "https://github.com"
|
||||
}
|
||||
|
||||
log.Infof("正在检查更新.")
|
||||
latest, err := GetLastVersion()
|
||||
if err != nil {
|
||||
log.Warnf("获取最新版本失败: %v", err)
|
||||
wait()
|
||||
}
|
||||
url := fmt.Sprintf("%v/johlanse/study_xxqg/releases/download/%v/%v", github, latest, binaryName())
|
||||
if baseVersion == latest {
|
||||
log.Info("当前版本已经是最新版本!")
|
||||
wait()
|
||||
}
|
||||
log.Info("当前最新版本为 ", latest)
|
||||
log.Warn("是否更新(y/N): ")
|
||||
r := strings.TrimSpace(readLine())
|
||||
if r != "y" && r != "Y" {
|
||||
log.Warn("已取消更新!")
|
||||
wait()
|
||||
}
|
||||
log.Info("正在更新,请稍等...")
|
||||
|
||||
err = update(url)
|
||||
if err != nil {
|
||||
log.Error("更新失败: ", err)
|
||||
} else {
|
||||
log.Info("更新成功!")
|
||||
}
|
||||
wait()
|
||||
}
|
||||
|
||||
func readLine() (str string) {
|
||||
console := bufio.NewReader(os.Stdin)
|
||||
str, _ = console.ReadString('\n')
|
||||
str = strings.TrimSpace(str)
|
||||
return
|
||||
}
|
||||
|
||||
func wait() {
|
||||
log.Info("按 Enter 继续....")
|
||||
readLine()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func GetLastVersion() (string, error) {
|
||||
var data string
|
||||
err := gout.GET("https://api.github.com/repos/johlanse/study_xxqg/releases/latest").BindBody(&data).Do()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return gjson.Get(data, "tag_name").Str, err
|
||||
}
|
||||
|
||||
func CheckVersion(oldVersion, newVersion string) bool {
|
||||
if oldVersion == "UnKnow" {
|
||||
log.Infoln("使用action版本或者自编译版本")
|
||||
return false
|
||||
}
|
||||
oldVersion = strings.ReplaceAll(oldVersion, ".", "")
|
||||
oldVersion = strings.ReplaceAll(oldVersion, "v", "")
|
||||
newVersion = strings.ReplaceAll(newVersion, ".", "")
|
||||
newVersion = strings.ReplaceAll(newVersion, "v", "")
|
||||
old, err := strconv.Atoi(oldVersion)
|
||||
newV, err := strconv.Atoi(newVersion)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return newV > old
|
||||
}
|
||||
|
||||
func binaryName() string {
|
||||
goarch := runtime.GOARCH
|
||||
if goarch == "arm" {
|
||||
goarch += "v7"
|
||||
}
|
||||
ext := "tar.gz"
|
||||
if runtime.GOOS == "windows" {
|
||||
ext = "zip"
|
||||
}
|
||||
return fmt.Sprintf("study_xxqg_%v_%v.%v", runtime.GOOS, goarch, ext)
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package utils
|
||||
|
||||
func update(url string) error {
|
||||
//resp, err := http.Get(url)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
//defer resp.Body.Close()
|
||||
//
|
||||
//reader, _ := zip.NewReader(bytes.NewReader(), resp.ContentLength)
|
||||
//_, err = reader.Open("go-cqhttp.exe")
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue