mirror of
https://codeberg.org/scip/kleingebaeck.git
synced 2025-12-16 20:11:01 +01:00
added support to calculate and store the ad expire date (#43)
This commit is contained in:
13
ad.go
13
ad.go
@@ -20,6 +20,7 @@ package main
|
||||
import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Index struct {
|
||||
@@ -37,6 +38,7 @@ type Ad struct {
|
||||
Created string `goquery:"#viewad-extra-info,text"`
|
||||
Text string `goquery:"p#viewad-description-text,html"`
|
||||
Images []string `goquery:".galleryimage-element img,[src]"`
|
||||
Expire string
|
||||
}
|
||||
|
||||
// Used by slog to pretty print an ad
|
||||
@@ -49,6 +51,8 @@ func (ad *Ad) LogValue() slog.Value {
|
||||
slog.Int("bodysize", len(ad.Text)),
|
||||
slog.String("categorytree", strings.Join(ad.CategoryTree, "+")),
|
||||
slog.String("condition", ad.Condition),
|
||||
slog.String("created", ad.Created),
|
||||
slog.String("expire", ad.Expire),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -67,3 +71,12 @@ func (ad *Ad) Incomplete() bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (ad *Ad) CalculateExpire() {
|
||||
if len(ad.Created) > 0 {
|
||||
ts, err := time.Parse("02.01.2006", ad.Created)
|
||||
if err == nil {
|
||||
ad.Expire = ts.AddDate(0, 2, 1).Format("02.01.2006")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user