mirror of
https://codeberg.org/scip/kleingebaeck.git
synced 2025-12-17 04:21:00 +01:00
Compare commits
2 Commits
fix/window
...
fix/crash-
| Author | SHA1 | Date | |
|---|---|---|---|
| b464a1bfaa | |||
| e838f71781 |
@@ -34,7 +34,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION string = "0.3.6"
|
||||
VERSION string = "0.3.4"
|
||||
Baseuri string = "https://www.kleinanzeigen.de"
|
||||
Listuri string = "/s-bestandsliste.html"
|
||||
Defaultdir string = "."
|
||||
|
||||
1
go.mod
1
go.mod
@@ -24,7 +24,6 @@ require (
|
||||
github.com/corona10/goimagehash v1.1.0 // indirect
|
||||
github.com/fatih/color v1.16.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/knadh/koanf/maps v0.1.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -15,8 +15,6 @@ github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
|
||||
github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
|
||||
github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs=
|
||||
|
||||
27
main.go
27
main.go
@@ -18,16 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/inconshreveable/mousetrap"
|
||||
"github.com/lmittmann/tint"
|
||||
"github.com/tlinden/yadu"
|
||||
)
|
||||
@@ -38,25 +35,6 @@ func main() {
|
||||
os.Exit(Main(os.Stdout))
|
||||
}
|
||||
|
||||
func init() {
|
||||
// if we're running on Windows AND if the user double clicked the
|
||||
// exe file from explorer, we tell them and then wait until any
|
||||
// key has been hit, which will make the cmd window disappear and
|
||||
// thus give the user time to read it.
|
||||
if runtime.GOOS == "windows" {
|
||||
if mousetrap.StartedByExplorer() {
|
||||
fmt.Println("Do no double click kleingebaeck.exe!")
|
||||
fmt.Println("Please open a command shell and run it from there.")
|
||||
fmt.Println()
|
||||
fmt.Print("Press any key to quit: ")
|
||||
_, err := bufio.NewReader(os.Stdin).ReadString('\n')
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Main(output io.Writer) int {
|
||||
logLevel := &slog.LevelVar{}
|
||||
opts := &tint.Options{
|
||||
@@ -138,6 +116,11 @@ func Main(output io.Writer) int {
|
||||
if err != nil {
|
||||
return Die(err)
|
||||
}
|
||||
|
||||
err = Mkdir(outdir)
|
||||
if err != nil {
|
||||
return Die(err)
|
||||
}
|
||||
conf.Outdir = outdir
|
||||
|
||||
// used for all HTTP requests
|
||||
|
||||
7
mkrel.sh
7
mkrel.sh
@@ -22,12 +22,7 @@ freebsd/amd64
|
||||
linux/amd64
|
||||
netbsd/amd64
|
||||
openbsd/amd64
|
||||
windows/amd64
|
||||
freebsd/arm64
|
||||
linux/arm64
|
||||
netbsd/arm64
|
||||
openbsd/arm64
|
||||
windows/arm64"
|
||||
windows/amd64"
|
||||
|
||||
tool="$1"
|
||||
version="$2"
|
||||
|
||||
15
scrape.go
15
scrape.go
@@ -126,32 +126,21 @@ func ScrapeAd(fetch *Fetcher, uri string) error {
|
||||
|
||||
advertisement.CalculateExpire()
|
||||
|
||||
// prepare ad dir name
|
||||
addir, err := AdDirName(fetch.Config, advertisement)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
proceed := CheckAdVisited(fetch.Config, addir)
|
||||
proceed := CheckAdVisited(fetch.Config, advertisement.Slug)
|
||||
if !proceed {
|
||||
return nil
|
||||
}
|
||||
|
||||
// write listing
|
||||
err = WriteAd(fetch.Config, advertisement, addir)
|
||||
addir, err := WriteAd(fetch.Config, advertisement)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// tell the user
|
||||
slog.Debug("extracted ad listing", "ad", advertisement)
|
||||
|
||||
// stats
|
||||
fetch.Config.IncrAds()
|
||||
|
||||
// register for later checks
|
||||
DirsVisited[addir] = 1
|
||||
|
||||
return ScrapeImages(fetch, advertisement, addir)
|
||||
}
|
||||
|
||||
|
||||
23
store.go
23
store.go
@@ -72,13 +72,19 @@ func AdDirName(conf *Config, advertisement *Ad) (string, error) {
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func WriteAd(conf *Config, advertisement *Ad, addir string) error {
|
||||
func WriteAd(conf *Config, advertisement *Ad) (string, error) {
|
||||
// prepare ad dir name
|
||||
addir, err := AdDirName(conf, advertisement)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// prepare output dir
|
||||
dir := filepath.Join(conf.Outdir, addir)
|
||||
|
||||
err := Mkdir(dir)
|
||||
err = Mkdir(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
// write ad file
|
||||
@@ -86,7 +92,7 @@ func WriteAd(conf *Config, advertisement *Ad, addir string) error {
|
||||
|
||||
listingfd, err := os.Create(listingfile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create Adlisting.txt: %w", err)
|
||||
return "", fmt.Errorf("failed to create Adlisting.txt: %w", err)
|
||||
}
|
||||
defer listingfd.Close()
|
||||
|
||||
@@ -98,17 +104,17 @@ func WriteAd(conf *Config, advertisement *Ad, addir string) error {
|
||||
|
||||
tmpl, err := tpl.New("adlisting").Parse(conf.Template)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse adlisting template: %w", err)
|
||||
return "", fmt.Errorf("failed to parse adlisting template: %w", err)
|
||||
}
|
||||
|
||||
err = tmpl.Execute(listingfd, advertisement)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute adlisting template: %w", err)
|
||||
return "", fmt.Errorf("failed to execute adlisting template: %w", err)
|
||||
}
|
||||
|
||||
slog.Info("wrote ad listing", "listingfile", listingfile)
|
||||
|
||||
return nil
|
||||
return addir, nil
|
||||
}
|
||||
|
||||
func WriteImage(filename string, reader *bytes.Reader) error {
|
||||
@@ -170,6 +176,9 @@ func CheckAdVisited(conf *Config, adname string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// register
|
||||
DirsVisited[adname] = 1
|
||||
|
||||
// overwrite
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user