docker
This commit is contained in:
9
.dockerignore
Normal file
9
.dockerignore
Normal file
@ -0,0 +1,9 @@
|
||||
.env
|
||||
.git/
|
||||
docker-compose.yml
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
tmp/
|
||||
.air.toml
|
||||
aparserserver/
|
||||
.vscode
|
25
Dockerfile
Normal file
25
Dockerfile
Normal file
@ -0,0 +1,25 @@
|
||||
FROM registry.home.4it.me/golang:1.21 as builder
|
||||
|
||||
LABEL maintainer="dilap54 <dilap54@mail.ru>"
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN make build
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
WORKDIR /app/
|
||||
|
||||
COPY migrations ./migrations
|
||||
COPY ./categories.json ./
|
||||
COPY --from=builder /app/cli ./
|
||||
|
||||
ENTRYPOINT [ "./cli" ]
|
10
Makefile
Normal file
10
Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
docker-build:
|
||||
docker build . -t registry.home.4it.me/dilap54/platiparser
|
||||
|
||||
docker-push:
|
||||
docker push registry.home.4it.me/dilap54/platiparser
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o cli ./cmd/cli/
|
@ -11,40 +11,45 @@ import (
|
||||
|
||||
"gitea.home.4it.me/dilap54/platiparser/gorm"
|
||||
"gitea.home.4it.me/dilap54/platiparser/plati"
|
||||
"github.com/joho/godotenv"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
godotenv.Load(".env")
|
||||
commands = append(commands, platiCommand)
|
||||
}
|
||||
|
||||
func main() {
|
||||
categories := openCategories("./categories.json").Content
|
||||
categories = filterBySubstring("Gift", categories)
|
||||
var platiCommand = &cli.Command{
|
||||
Name: "plati",
|
||||
Action: func(c *cli.Context) error {
|
||||
categories := openCategories("./categories.json").Content
|
||||
categories = filterBySubstring("Gift", categories)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.Background()
|
||||
|
||||
db := gorm.GetDB()
|
||||
platiCli := plati.New()
|
||||
db := gorm.GetDB()
|
||||
platiCli := plati.New()
|
||||
|
||||
// printNames(categories)
|
||||
// printNames(categories)
|
||||
|
||||
for i, c := range categories {
|
||||
log.Printf("fetching goods [%d/%d] for %s\n", i, len(categories), c.FlatName)
|
||||
goods, err := platiCli.GetBlockGoodsCategory(ctx, c.ID, c.ParentID, "cntSellDESC", 1, 100, "RUR", "ru-RU")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
for i, c := range categories {
|
||||
log.Printf("fetching goods [%d/%d] for %s\n", i, len(categories), c.FlatName)
|
||||
goods, err := platiCli.GetBlockGoodsCategory(ctx, c.ID, c.ParentID, "cntSellDESC", 1, 100, "RUR", "ru-RU")
|
||||
if err != nil {
|
||||
return fmt.Errorf("getblockgoodscategory: %w", err)
|
||||
}
|
||||
if len(goods) == 0 {
|
||||
continue
|
||||
}
|
||||
gormGoods := convertGoodsToGorm(c, goods)
|
||||
if err := db.Create(gormGoods).Error; err != nil {
|
||||
return fmt.Errorf("db Create: %w", err)
|
||||
}
|
||||
json.NewEncoder(os.Stdout).Encode(goods)
|
||||
}
|
||||
if len(goods) == 0 {
|
||||
continue
|
||||
}
|
||||
gormGoods := convertGoodsToGorm(c, goods)
|
||||
if err := db.Create(gormGoods).Error; err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
json.NewEncoder(os.Stdout).Encode(goods)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func convertGoodsToGorm(cat *plati.Category, goods []*plati.Good) []*gorm.Good {
|
Reference in New Issue
Block a user