From d5885854ecbc2b4974cd97205a1ef24de7ded74d Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Thu, 6 Feb 2025 20:09:46 +0100 Subject: [PATCH] add color detail as well --- README.md | 1 + ad.go | 5 +++++ config.go | 6 +++--- kleingebaeck.1 | 3 ++- kleingebaeck.go | 1 + kleingebaeck.pod | 1 + main_test.go | 8 ++++++++ scrape.go | 8 +++++--- 8 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 78f03ba..df58530 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,7 @@ Price: 99 € VB Id: 1919191919 Category: Sachbücher Condition: Sehr Gut +Type: Buch Created: 10.12.2023 This is the description text. diff --git a/ad.go b/ad.go index 22ccdc0..ac479ba 100644 --- a/ad.go +++ b/ad.go @@ -34,6 +34,7 @@ type Ad struct { Details []string `goquery:".addetailslist--detail--value,text"` Condition string // post processed from details Type string // post processed from details + Color string // post processed from details Category string CategoryTree []string `goquery:".breadcrump-link,text"` Price string `goquery:"h2#viewad-price"` @@ -60,6 +61,10 @@ func (ad *Ad) LogValue() slog.Value { // static set of conditions available, used for post processing details var CONDITIONS = []string{"Neu", "Gut", "Sehr Gut", "In Ordnung"} +var COLORS = []string{"Beige", "Blau", "Braun", "Bunt", "Burgunderrot", + "Creme", "Gelb", "Gold", "Grau", "Grün", "Holz", "Khaki", "Lavelndel", + "Lila", "Orange", "Pink", "Print", "Rot", "Schwarz", "Silber", + "Transparent", "Türkis", "Weiß", "Sonstige"} // check for completeness. I erected these fields to be mandatory // (though I really don't know if they really are). I consider images diff --git a/config.go b/config.go index 6f1bae9..8f6613d 100644 --- a/config.go +++ b/config.go @@ -34,17 +34,17 @@ import ( ) const ( - VERSION string = "0.3.14" + VERSION string = "0.3.15" Baseuri string = "https://www.kleinanzeigen.de" Listuri string = "/s-bestandsliste.html" Defaultdir string = "." DefaultTemplate string = "Title: {{.Title}}\nPrice: {{.Price}}\nId: {{.ID}}\n" + - "Category: {{.Category}}\nCondition: {{.Condition}}\nType: {{.Type}}\n" + + "Category: {{.Category}}\nCondition: {{.Condition}}\nType: {{.Type}}\nColor: {{.Color}}\n" + "Created: {{.Created}}\nExpire: {{.Expire}}\n\n{{.Text}}\n" DefaultTemplateWin string = "Title: {{.Title}}\r\nPrice: {{.Price}}\r\nId: {{.ID}}\r\n" + - "Category: {{.Category}}\r\nCondition: {{.Condition}}\r\nType: {{.Type}}\r\n" + + "Category: {{.Category}}\r\nCondition: {{.Condition}}\r\nType: {{.Type}}\r\nColor: {{.Color}}\r\n" + "Created: {{.Created}}\r\nExpires: {{.Expire}}\r\n\r\n{{.Text}}\r\n" DefaultUserAgent string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + diff --git a/kleingebaeck.1 b/kleingebaeck.1 index ab38d62..96aaf50 100644 --- a/kleingebaeck.1 +++ b/kleingebaeck.1 @@ -174,7 +174,7 @@ well. We use \s-1TOML\s0 as our configuration language. See .PP Format is pretty simple: .PP -.Vb 12 +.Vb 10 \& user = 1010101 \& loglevel = verbose \& outdir = "test" @@ -186,6 +186,7 @@ Format is pretty simple: \& Category: {{.Category}} \& Condition: {{.Condition}} \& Type: {{.Type}} +\& Color: {{.Color}} \& Created: {{.Created}} \& \& {{.Text}} diff --git a/kleingebaeck.go b/kleingebaeck.go index 4fbf9fe..705fb4a 100644 --- a/kleingebaeck.go +++ b/kleingebaeck.go @@ -47,6 +47,7 @@ CONFIGURATION Category: {{.Category}} Condition: {{.Condition}} Type: {{.Type}} + Color: {{.Color}} Created: {{.Created}} {{.Text}} diff --git a/kleingebaeck.pod b/kleingebaeck.pod index 522c84f..7737a30 100644 --- a/kleingebaeck.pod +++ b/kleingebaeck.pod @@ -47,6 +47,7 @@ Format is pretty simple: Category: {{.Category}} Condition: {{.Condition}} Type: {{.Type}} + Color: {{.Color}} Created: {{.Created}} {{.Text}} diff --git a/main_test.go b/main_test.go index 1a0fd7b..07b5115 100644 --- a/main_test.go +++ b/main_test.go @@ -93,6 +93,10 @@ const ADTPL string = `DOCTYPE html>
  • Zustand {{ .Condition }} + Farbe + {{ .Color }} + Art + {{ .Type }}
  • @@ -251,6 +255,8 @@ type AdConfig struct { Price string Category string Condition string + Type string + Color string Created string Text string Images []string // files in ./t/ @@ -265,6 +271,8 @@ var adsrc = []AdConfig{ Text: "Thing to sale", Slug: "first-ad", Condition: "Sehr Gut", + Color: "Grün", + Type: "Ball", Created: "Yesterday", Images: []string{"t/1.jpg", "t/2.jpg"}, }, diff --git a/scrape.go b/scrape.go index 6289067..2774125 100644 --- a/scrape.go +++ b/scrape.go @@ -126,12 +126,14 @@ func ScrapeAd(fetch *Fetcher, uri string) error { } for _, detail := range advertisement.Details { - if slices.Contains(CONDITIONS, detail) { + switch { + case slices.Contains(CONDITIONS, detail): advertisement.Condition = detail - } else { + case slices.Contains(COLORS, detail): + advertisement.Color = detail + default: advertisement.Type = detail } - } advertisement.CalculateExpire()