mirror of
https://codeberg.org/scip/kleingebaeck.git
synced 2025-12-17 12:31:03 +01:00
Dev (#8)
* fixed conf parsing: variables can now be omitted from the config * fix newlines: use CRLF on windows * bump version --------- Co-authored-by: Thomas von Dein <tom@vondein.org>
This commit is contained in:
12
config.go
12
config.go
@@ -23,21 +23,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION string = "0.0.5"
|
VERSION string = "0.0.6"
|
||||||
Baseuri string = "https://www.kleinanzeigen.de"
|
Baseuri string = "https://www.kleinanzeigen.de"
|
||||||
Listuri string = "/s-bestandsliste.html"
|
Listuri string = "/s-bestandsliste.html"
|
||||||
Defaultdir string = "."
|
Defaultdir string = "."
|
||||||
DefaultTemplate string = "Title: {{.Title}}\nPrice: {{.Price}}\nId: {{.Id}}\n" +
|
DefaultTemplate string = "Title: {{.Title}}\nPrice: {{.Price}}\nId: {{.Id}}\n" +
|
||||||
"Category: {{.Category}}\nCondition: {{.Condition}}\nCreated: {{.Created}}\n\n{{.Text}}\n"
|
"Category: {{.Category}}\nCondition: {{.Condition}}\nCreated: {{.Created}}\n\n{{.Text}}\n"
|
||||||
|
DefaultTemplateWin string = "Title: {{.Title}}\r\nPrice: {{.Price}}\r\nId: {{.Id}}\r\n" +
|
||||||
|
"Category: {{.Category}}\r\nCondition: {{.Condition}}\r\nCreated: {{.Created}}\r\n\r\n{{.Text}}\r\n"
|
||||||
Useragent string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
|
Useragent string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
|
||||||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Verbose bool `hcl:"verbose"`
|
Verbose *bool `hcl:"verbose"`
|
||||||
User int `hcl:"user"`
|
User *int `hcl:"user"`
|
||||||
Outdir string `hcl:"outdir"`
|
Outdir *string `hcl:"outdir"`
|
||||||
Template string `hcl:"template"`
|
Template *string `hcl:"template"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfigfile(file string) (*Config, error) {
|
func ParseConfigfile(file string) (*Config, error) {
|
||||||
|
|||||||
18
main.go
18
main.go
@@ -22,6 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
|
||||||
"github.com/lmittmann/tint"
|
"github.com/lmittmann/tint"
|
||||||
@@ -109,7 +110,7 @@ func Main() int {
|
|||||||
return Die(err)
|
return Die(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if enableverbose || conf.Verbose {
|
if enableverbose || *conf.Verbose {
|
||||||
logLevel.Set(slog.LevelInfo)
|
logLevel.Set(slog.LevelInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,8 +136,8 @@ func Main() int {
|
|||||||
slog.Debug("config", "conf", conf)
|
slog.Debug("config", "conf", conf)
|
||||||
|
|
||||||
if len(dir) == 0 {
|
if len(dir) == 0 {
|
||||||
if len(conf.Outdir) > 0 {
|
if len(*conf.Outdir) > 0 {
|
||||||
dir = conf.Outdir
|
dir = *conf.Outdir
|
||||||
} else {
|
} else {
|
||||||
dir = Defaultdir
|
dir = Defaultdir
|
||||||
}
|
}
|
||||||
@@ -150,8 +151,11 @@ func Main() int {
|
|||||||
|
|
||||||
// which template to use
|
// which template to use
|
||||||
template := DefaultTemplate
|
template := DefaultTemplate
|
||||||
if len(conf.Template) > 0 {
|
if runtime.GOOS == "windows" {
|
||||||
template = conf.Template
|
template = DefaultTemplateWin
|
||||||
|
}
|
||||||
|
if len(*conf.Template) > 0 {
|
||||||
|
template = *conf.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
// directly backup ad listing[s]
|
// directly backup ad listing[s]
|
||||||
@@ -167,8 +171,8 @@ func Main() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// backup all ads of the given user (via config or cmdline)
|
// backup all ads of the given user (via config or cmdline)
|
||||||
if uid == 0 && conf.User > 0 {
|
if uid == 0 && *conf.User > 0 {
|
||||||
uid = conf.User
|
uid = *conf.User
|
||||||
}
|
}
|
||||||
|
|
||||||
if uid > 0 {
|
if uid > 0 {
|
||||||
|
|||||||
7
store.go
7
store.go
@@ -22,6 +22,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
tpl "text/template"
|
tpl "text/template"
|
||||||
)
|
)
|
||||||
@@ -41,7 +42,11 @@ func WriteAd(dir string, ad *Ad, template string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ad.Text = strings.ReplaceAll(ad.Text, "<br/>", "\n")
|
if runtime.GOOS == "windows" {
|
||||||
|
ad.Text = strings.ReplaceAll(ad.Text, "<br/>", "\r\n")
|
||||||
|
} else {
|
||||||
|
ad.Text = strings.ReplaceAll(ad.Text, "<br/>", "\n")
|
||||||
|
}
|
||||||
|
|
||||||
tmpl, err := tpl.New("adlisting").Parse(template)
|
tmpl, err := tpl.New("adlisting").Parse(template)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user