eljur/main.go
2024-01-27 21:43:07 +03:00

41 lines
1.3 KiB
Go

package main
import (
"strings"
"time"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
)
func run(browser *rod.Browser, LOGIN, PASSWORD, ELJUR_URL, TELEGRAM_CHAT_ID, TELEGRAM_API_URL string) {
new_table, new_last_post := scape(browser, LOGIN, PASSWORD, ELJUR_URL)
old_table := get_file("data/table.html")
old_last_post := ""
if strings.Contains(old_table, `<div class="board-item__footer">`) {
old_last_post = old_table[strings.Index(old_table, `<h1 class="page-title">Объявления</h1>`):strings.Index(old_table, `<div class="board-item__footer">`)]
}
if new_table != " " && new_table != old_table {
update_file(new_table, "data/table.html")
if new_last_post != old_last_post {
send_photo("data/last_post.png", TELEGRAM_API_URL, TELEGRAM_CHAT_ID)
} else {
send_photo("data/sad.png", TELEGRAM_API_URL, TELEGRAM_CHAT_ID)
}
get_difference(old_table, new_table)
send_document("data/difference.html", TELEGRAM_API_URL, TELEGRAM_CHAT_ID)
}
}
func main() {
LOGIN, PASSWORD, ELJUR_URL, TELEGRAM_CHAT_ID, TELEGRAM_API_URL := load_env_vars()
path, _ := launcher.LookPath()
launcher := launcher.New().Bin(path).MustLaunch()
browser := rod.New().ControlURL(launcher).MustConnect()
for {
run(browser, LOGIN, PASSWORD, ELJUR_URL, TELEGRAM_CHAT_ID, TELEGRAM_API_URL)
time.Sleep(400 * time.Second)
}
}