107 lines
3.2 KiB
Go
107 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/json"
|
|
"fmt"
|
|
"local/sandbox/selenium/copart/copart/auction"
|
|
"local/storage"
|
|
"log"
|
|
"net/url"
|
|
"os"
|
|
"regexp"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
storage.DefaultNamespace = "namespace"
|
|
s, err := storage.New(storage.BOLT, "./bolt.db")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
log.Println(s)
|
|
|
|
f, err := os.Open("./log2")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer f.Close()
|
|
|
|
list := []string{}
|
|
|
|
scn := bufio.NewScanner(f)
|
|
for scn.Scan() {
|
|
line := scn.Text()
|
|
if strings.Contains(line, "true = ") {
|
|
continue
|
|
}
|
|
m := regexp.MustCompile("\\[[^\\]]+\\]").FindAllString(line, 2)[1]
|
|
between := func(l, a, b string) string {
|
|
form := fmt.Sprintf("%s:[^(%s)]*%s", a, b, b)
|
|
c := regexp.MustCompile(form).FindString(l)
|
|
c = strings.TrimPrefix(c, fmt.Sprintf("%s:", a))
|
|
c = strings.TrimSuffix(c, fmt.Sprintf("%s", b))
|
|
return strings.TrimSpace(c)
|
|
}
|
|
bid := between(m, "bid", "title")
|
|
title := between(m, "title", "watched")
|
|
when := between(m, "when", "\\]")
|
|
when = regexp.MustCompile(":[0-9][0-9]\\.[0-9].*$").ReplaceAllString(when, "")
|
|
c := auction.NewCar()
|
|
c.Bid = bid
|
|
c.Title = title
|
|
c.TS, _ = time.Parse("2006-01-02 15:04", regexp.MustCompile(":[0-9][0-9]\\.[0-9].*$").ReplaceAllString(when, ""))
|
|
c.Details = map[string]string{
|
|
"Year": strings.Split(title, " ")[0],
|
|
}
|
|
c.Images = []*auction.Image{}
|
|
srcs := []string{}
|
|
if strings.Contains(c.Title, "CHEVROLET") {
|
|
srcs = []string{
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX133/eb332bcb-4d51-422c-a317-8bfb3729f368.JPG",
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX133/fb3ac542-bb52-4554-98a9-3979fed5edb1.JPG",
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX133/5c974805-c917-495a-8481-5e697a46ac25.JPG",
|
|
}
|
|
} else if strings.Contains(c.Title, "YUKON") {
|
|
srcs = []string{
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX145/c64e1510-9e81-4128-a285-e4cc45036670.JPG",
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX145/1ef2b374-5245-458c-a540-11ed1ea81f9b.JPG",
|
|
}
|
|
} else if strings.Contains(c.Title, "JEEP") {
|
|
srcs = []string{
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX137/8c9d27d3-3642-499c-86de-0bee685e116e.JPG",
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX137/d7b160cc-c171-473d-851f-c92bf3a58ee6.JPG",
|
|
}
|
|
} else if strings.Contains(c.Title, "HONDA") {
|
|
srcs = []string{
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX133/c9504579-3f31-4278-b020-2b1b37867c82.JPG",
|
|
}
|
|
} else if strings.Contains(c.Title, "MAZDA 3") {
|
|
srcs = []string{
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX133/fbc946db-bb03-4624-b8d4-b7723722c0d5.JPG",
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX133/3892e997-ca0c-4270-86cb-94b98cdfd28e.JPG",
|
|
"https://cs.copart.com/v1/AUTH_svc.pdoc00001/PIX133/3bee196b-219f-4b6b-b8cf-9d2797ab5113.JPG",
|
|
}
|
|
}
|
|
for _, src := range srcs {
|
|
u, _ := url.Parse(src)
|
|
c.Images = append(c.Images, &auction.Image{Src: u})
|
|
}
|
|
log.Println(c)
|
|
if b, err := c.Encode(); err != nil {
|
|
panic(err)
|
|
} else if err := s.Set(c.String(), b); err != nil {
|
|
panic(err)
|
|
}
|
|
list = append(list, c.String())
|
|
}
|
|
if err := scn.Err(); err != nil {
|
|
panic(err)
|
|
}
|
|
b, _ := json.Marshal(list)
|
|
if err := s.Set("LIST", b); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|