summaryrefslogtreecommitdiff
path: root/crawler/database.go
diff options
context:
space:
mode:
Diffstat (limited to 'crawler/database.go')
-rw-r--r--crawler/database.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/crawler/database.go b/crawler/database.go
index d617722..e11c80b 100644
--- a/crawler/database.go
+++ b/crawler/database.go
@@ -88,13 +88,16 @@ func (app *App) createTables() error {
return err
}
+/**
+ * Saves scrapped offers in database. Detects which offers are new. Runs inside tx.
+ */
func (app *App) save_offer(W []Angebot) error {
query := `INSERT INTO angebot (shop, name, url, abv, volume, age, original_price, discounted_price, base_price, valid_until, image_url, website_raw, spirit_type, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
stmt, err := app.Tx.Prepare(query)
if err != nil {
- Debug(err, "Save Offer: Preparing query failed")
+ Warn(err, "Save Offer: Preparing query failed")
return err
}
defer stmt.Close()
@@ -135,10 +138,12 @@ func (app *App) save_offer(W []Angebot) error {
}*/
}
- //return app.remove_expired(W)
return nil
}
+/**
+ * Invalidates expired offers by updating 'valid_until' column. Detects which offers are expired. Runs inside Tx.
+ */
func (app *App) remove_expired(W []Angebot, shop Shop) error {
query := `SELECT id, name, shop, volume, abv, original_price, discounted_price FROM angebot WHERE shop = ? AND created_at < ?
@@ -146,7 +151,7 @@ func (app *App) remove_expired(W []Angebot, shop Shop) error {
rows, err := app.Tx.Queryx(query, shop.Id, app.Now, app.Now)
if err != nil {
- Debug(err, "Remove expired: Query failed")
+ Warn(err, "Remove expired: Query failed")
return err
}
defer rows.Close()
@@ -156,7 +161,7 @@ func (app *App) remove_expired(W []Angebot, shop Shop) error {
err = rows.StructScan(&offer_db)
if err != nil {
- Debug(err, "Remove expired: Struct scan failed")
+ Warn(err, "Remove expired: Struct scan failed")
return err
}