Release 0.2.0
- new language: go - new shops: cybertek.fr, mediamarkt.ch - deprecated shops: alternate.be, minershop.eu - improved database transaction management - better web parsing library (ferret, requires headless chrome browser) - include or exclude products by applying regex on their names - check for PID file to avoid running the bot twice - hastags are now configurable Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
31bcbc51dd
commit
3a4aba93e5
26 changed files with 1354 additions and 1054 deletions
45
models.go
Normal file
45
models.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Product is self-explainatory
|
||||
type Product struct {
|
||||
gorm.Model
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
URL string `gorm:"unique" json:"url"`
|
||||
Price float64 `gorm:"not null" json:"price"`
|
||||
PriceCurrency string `gorm:"not null" json:"price_currency"`
|
||||
Available bool `gorm:"not null;default:false" json:"available"`
|
||||
ShopID uint
|
||||
Shop Shop
|
||||
}
|
||||
|
||||
// Equal compares a database product to another product
|
||||
func (p *Product) Equal(other *Product) bool {
|
||||
return p.URL == other.URL && p.Available == other.Available
|
||||
}
|
||||
|
||||
// IsValid returns true when a Product has all required values
|
||||
func (p *Product) IsValid() bool {
|
||||
return p.Name != "" && p.URL != "" && p.Price != 0 && p.PriceCurrency != ""
|
||||
}
|
||||
|
||||
// Merge one product with another
|
||||
func (p *Product) Merge(o *Product) {
|
||||
p.Price = o.Price
|
||||
p.PriceCurrency = o.PriceCurrency
|
||||
p.Available = o.Available
|
||||
}
|
||||
|
||||
// ToMerge detects if a product needs to be merged with another one
|
||||
func (p *Product) ToMerge(o *Product) bool {
|
||||
return p.Price != o.Price || p.PriceCurrency != o.PriceCurrency || p.Available != o.Available
|
||||
}
|
||||
|
||||
// Shop represents a retailer website
|
||||
type Shop struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Name string `gorm:"unique"`
|
||||
}
|
||||
Reference in a new issue