selenium/copart/main.go

81 lines
1.4 KiB
Go
Executable File

package main
import (
"local/sandbox/selenium/copart/copart/auction"
"local/sandbox/selenium/copart/copart/browser"
"local/sandbox/selenium/copart/copart/config"
"local/sandbox/selenium/copart/copart/server"
"log"
"os"
"os/signal"
"sync"
"syscall"
"time"
)
func main() {
log.SetPrefix("..")
time.Local = time.FixedZone("UTC-6", (-6*int(time.Hour))/int(time.Second))
sigc := make(chan os.Signal)
// TODO if time is FRI 5PM -> MON 7 AM, then EXIT
if err := config.New(); err != nil {
panic(err)
}
log.Println(config.Values())
s := server.New()
if err := s.Routes(); err != nil {
panic(err)
}
go func(c chan os.Signal) {
if err := s.Run(); err != nil {
log.Println(err)
}
c <- syscall.SIGINT
}(sigc)
today, err := auction.NewToday(sigc)
defer today.Stop()
if err != nil {
panic(err)
}
if err := today.Start(); err != nil {
panic(err)
}
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT,
)
<-sigc
today.Stop()
config.Values().DB.Close()
}
func test_parallel() {
wg := &sync.WaitGroup{}
for i := 0; i < 30; i++ {
wg.Add(1)
go func() {
defer wg.Done()
b, err := browser.New()
if err != nil {
log.Println(err)
return
}
defer b.Close()
if err := b.Get("https://www.google.com"); err != nil {
log.Println(err)
return
}
log.Println(b.Driver.FindElements("xpath", "//div[1]"))
}()
}
wg.Wait()
}