Compare commits

..

9 Commits

Author SHA1 Message Date
62bda54d98 feat: adjust waiting times 2023-07-02 23:56:23 +02:00
0933174ea1 fix bug 2023-07-02 23:28:38 +02:00
bf700eeeb3 feat add log date 2023-07-02 23:13:30 +02:00
bbc94e0375 polish logs 2023-07-02 23:08:07 +02:00
ad8ed58366 feat increase wait 2023-07-02 22:16:17 +02:00
db9f7495aa increase wait time after login submit 2023-07-02 22:14:31 +02:00
0ae922e58d feat: change jquery to pure js 2023-07-02 21:28:53 +02:00
fc35559ab8 feat wait a little more 2023-07-02 20:16:34 +02:00
c09933767b feat: archer add print message 2023-07-02 20:15:54 +02:00
2 changed files with 18 additions and 6 deletions

View File

@@ -29,11 +29,11 @@ func NewArcherAx50(page *rod.Page) ArcherAx50 {
} }
func (p ArcherAx50) Login(user, pass string) error { func (p ArcherAx50) Login(user, pass string) error {
time.Sleep(time.Millisecond * 1250) time.Sleep(time.Millisecond * 5550)
p.page.MustEvaluate(&rod.EvalOptions{ p.page.MustEvaluate(&rod.EvalOptions{
JS: `() => { JS: `() => {
$("input.password-text").each((i,v) => { document.querySelectorAll("input.password-text").forEach((v, i) => {
v.click(); v.click();
v.focus(); v.focus();
v.value="` + pass + `"; v.value="` + pass + `";
@@ -41,6 +41,7 @@ func (p ArcherAx50) Login(user, pass string) error {
return ''; return '';
}`, }`,
}) })
time.Sleep(time.Millisecond * 250) time.Sleep(time.Millisecond * 250)
log.Println(p.passwordID, "DONE") log.Println(p.passwordID, "DONE")
@@ -51,12 +52,12 @@ func (p ArcherAx50) Login(user, pass string) error {
} }
login.MustClick() login.MustClick()
log.Println(p.loginButtonID, "DONE") log.Println(p.loginButtonID, "DONE")
time.Sleep(time.Millisecond * 400) time.Sleep(time.Millisecond * 1550)
return nil return nil
} }
func (p ArcherAx50) SwitchWIFI() error { func (p ArcherAx50) SwitchWIFI() error {
time.Sleep(time.Second * 1) time.Sleep(time.Millisecond * 1850)
pageURL := p.page.MustInfo().URL pageURL := p.page.MustInfo().URL
log.Println("p.page.MustInfo().URL", pageURL) log.Println("p.page.MustInfo().URL", pageURL)
@@ -67,7 +68,7 @@ func (p ArcherAx50) SwitchWIFI() error {
wirelessTab.MustClick() wirelessTab.MustClick()
log.Println(p.wirelessTab, "DONE") log.Println(p.wirelessTab, "DONE")
time.Sleep(time.Millisecond * 750) time.Sleep(time.Millisecond * 1850)
checked := p.page.MustEvaluate(&rod.EvalOptions{ checked := p.page.MustEvaluate(&rod.EvalOptions{
JS: `() => { JS: `() => {
return document.getElementById('` + p.chkWifi2gID + `').checked; return document.getElementById('` + p.chkWifi2gID + `').checked;
@@ -75,6 +76,7 @@ func (p ArcherAx50) SwitchWIFI() error {
}) })
isChecked := checked.Value.Bool() isChecked := checked.Value.Bool()
log.Println(getCheckedMessage(isChecked))
p.page.MustEvaluate(&rod.EvalOptions{ p.page.MustEvaluate(&rod.EvalOptions{
JS: `() => { JS: `() => {
document.getElementById('` + p.chkWifi2gID + `').checked=` + fmt.Sprint(!isChecked) + `; document.getElementById('` + p.chkWifi2gID + `').checked=` + fmt.Sprint(!isChecked) + `;
@@ -82,6 +84,7 @@ func (p ArcherAx50) SwitchWIFI() error {
}`, }`,
}) })
time.Sleep(time.Millisecond * 150)
log.Println(p.chkWifi2gID, "DONE") log.Println(p.chkWifi2gID, "DONE")
saveButton, err := p.page.Element(p.saveButtonID) saveButton, err := p.page.Element(p.saveButtonID)
if err != nil { if err != nil {
@@ -90,6 +93,14 @@ func (p ArcherAx50) SwitchWIFI() error {
saveButton.MustClick() saveButton.MustClick()
log.Println(p.saveButtonID, "DONE") log.Println(p.saveButtonID, "DONE")
time.Sleep(time.Millisecond * 1500) time.Sleep(time.Millisecond * 5500)
return nil return nil
} }
func getCheckedMessage(isChecked bool) string {
if isChecked {
return "Time to sleep, let's switch off"
}
return "Time to laborate, let's switch WIFI on"
}

View File

@@ -22,6 +22,7 @@ func main() {
} }
config := cfg.NewConfig(envFile) config := cfg.NewConfig(envFile)
log.SetFlags(log.Ldate)
log.SetFlags(log.Lmicroseconds) log.SetFlags(log.Lmicroseconds)
if config.LogFile { if config.LogFile {
logFileName := fmt.Sprintf("%s.txt", time.Now().Format(strings.ReplaceAll(time.RFC1123Z, ":", "_"))) logFileName := fmt.Sprintf("%s.txt", time.Now().Format(strings.ReplaceAll(time.RFC1123Z, ":", "_")))