docker
This commit is contained in:
@ -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