From 4030d04b066acfab575f13056d6a9a6b5cf09c95 Mon Sep 17 00:00:00 2001 From: "T.v.Dein" Date: Thu, 27 Feb 2025 17:58:05 +0100 Subject: [PATCH] Add year,month,day support to Adnametemplate (#123) * add year, month and day to adnametemplate as well --- ad.go | 5 ++++- config.go | 2 +- kleingebaeck.1 | 27 +++++++++++++++++++++++++-- kleingebaeck.go | 12 +++++++++++- kleingebaeck.pod | 23 ++++++++++++++++++++++- scrape.go | 10 ++++++++-- 6 files changed, 71 insertions(+), 8 deletions(-) diff --git a/ad.go b/ad.go index 94fc38c..2327efe 100644 --- a/ad.go +++ b/ad.go @@ -1,5 +1,5 @@ /* -Copyright © 2023-2024 Thomas von Dein +Copyright © 2023-2025 Thomas von Dein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,6 +45,9 @@ type Ad struct { Text string `goquery:"p#viewad-description-text,html"` Images []string `goquery:".galleryimage-element img,[src]"` Expire string + + // runtime computed + Year, Day, Month string } // Used by slog to pretty print an ad diff --git a/config.go b/config.go index 27729be..c33838f 100644 --- a/config.go +++ b/config.go @@ -34,7 +34,7 @@ import ( ) const ( - VERSION string = "0.3.17" + VERSION string = "0.3.18" Baseuri string = "https://www.kleinanzeigen.de" Listuri string = "/s-bestandsliste.html" Defaultdir string = "." diff --git a/kleingebaeck.1 b/kleingebaeck.1 index 0667b43..791f217 100644 --- a/kleingebaeck.1 +++ b/kleingebaeck.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "KLEINGEBAECK 1" -.TH KLEINGEBAECK 1 "2025-02-10" "1" "User Commands" +.TH KLEINGEBAECK 1 "2025-02-27" "1" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -260,6 +260,29 @@ The ad directory name can be modified using the following ad values: .PP It can only be configured in the config file. By default only \&\f(CW\*(C`{{.Slug}}\*(C'\fR is being used, this is the title of the ad in url format. +.SS "\s-1AD NAME TEMPLATE\s0" +.IX Subsection "AD NAME TEMPLATE" +The name of the directory per ad can be tuned as well: +.ie n .IP """{{.Year}}""" 4 +.el .IP "\f(CW{{.Year}}\fR" 4 +.IX Item "{{.Year}}" +.PD 0 +.ie n .IP """{{.Month}}""" 4 +.el .IP "\f(CW{{.Month}}\fR" 4 +.IX Item "{{.Month}}" +.ie n .IP """{{.Day}}""" 4 +.el .IP "\f(CW{{.Day}}\fR" 4 +.IX Item "{{.Day}}" +.ie n .IP """{{.Slug}}""" 4 +.el .IP "\f(CW{{.Slug}}\fR" 4 +.IX Item "{{.Slug}}" +.ie n .IP """{{.Category}}""" 4 +.el .IP "\f(CW{{.Category}}\fR" 4 +.IX Item "{{.Category}}" +.ie n .IP """{{.ID}}""" 4 +.el .IP "\f(CW{{.ID}}\fR" 4 +.IX Item "{{.ID}}" +.PD .SS "\s-1AD TEMPLATE\s0" .IX Subsection "AD TEMPLATE" The ad listing itself can be modified as well, using the same @@ -344,7 +367,7 @@ Also there's currently no parallelization implemented. This will change in the future. .SH "LICENSE" .IX Header "LICENSE" -Copyright 2023\-2024 Thomas von Dein +Copyright 2023\-2025 Thomas von Dein .PP This program is free software: you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by diff --git a/kleingebaeck.go b/kleingebaeck.go index d15e567..d85b8e0 100644 --- a/kleingebaeck.go +++ b/kleingebaeck.go @@ -100,6 +100,16 @@ TEMPLATES It can only be configured in the config file. By default only "{{.Slug}}" is being used, this is the title of the ad in url format. + AD NAME TEMPLATE + The name of the directory per ad can be tuned as well: + + "{{.Year}}" + "{{.Month}}" + "{{.Day}}" + "{{.Slug}}" + "{{.Category}}" + "{{.ID}}" + AD TEMPLATE The ad listing itself can be modified as well, using the same variables as the ad name template above. @@ -174,7 +184,7 @@ LIMITATIONS in the future. LICENSE - Copyright 2023-2024 Thomas von Dein + Copyright 2023-2025 Thomas von Dein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the diff --git a/kleingebaeck.pod b/kleingebaeck.pod index 3b8dfd4..c85bc89 100644 --- a/kleingebaeck.pod +++ b/kleingebaeck.pod @@ -119,6 +119,27 @@ The ad directory name can be modified using the following ad values: It can only be configured in the config file. By default only C<{{.Slug}}> is being used, this is the title of the ad in url format. +=head2 AD NAME TEMPLATE + +The name of the directory per ad can be tuned as well: + +=over + +=item C<{{.Year}}> + +=item C<{{.Month}}> + +=item C<{{.Day}}> + +=item C<{{.Slug}}> + +=item C<{{.Category}}> + +=item C<{{.ID}}> + + +=back + =head2 AD TEMPLATE The ad listing itself can be modified as well, using the same @@ -202,7 +223,7 @@ change in the future. =head1 LICENSE -Copyright 2023-2024 Thomas von Dein +Copyright 2023-2025 Thomas von Dein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/scrape.go b/scrape.go index 2b279e0..39c8039 100644 --- a/scrape.go +++ b/scrape.go @@ -1,5 +1,5 @@ /* -Copyright © 2023-2024 Thomas von Dein +Copyright © 2023-2025 Thomas von Dein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -88,7 +88,13 @@ func ScrapeUser(fetch *Fetcher) error { // scrape an ad. uri is the full uri of the ad, dir is the basedir func ScrapeAd(fetch *Fetcher, uri string) error { - advertisement := &Ad{} + now := time.Now() + + advertisement := &Ad{ + Year: now.Format("2006"), + Month: now.Format("01"), + Day: now.Format("02"), + } // extract slug and id from uri uriparts := strings.Split(uri, "/")