~ghost08/ratt

small config changes and added behaviour for empty next url v1 PROPOSED

Daniel Hecker: 3
 Do not try to use empty string as url
 Get all press releases until no next page exists
 Store content in variable

 3 files changed, 8 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~ghost08/ratt/patches/27894/mbox | git am -3
Learn more about email & git

[PATCH 1/3] Do not try to use empty string as url Export this patch

---
 feed.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/feed.go b/feed.go
index 7c7bdb2..7774b12 100644
--- a/feed.go
+++ b/feed.go
@@ -161,6 +161,10 @@ func ConstructFeed(doc *goquery.Document, u string, selectors Selectors, verbose
			return nil, fmt.Errorf("getting next page link: %w", err)
		}
	}
	// do not try to resolve empty link
	if (nextLink == "") {
		return feed, nil
	}
	nextURL, err := url.Parse(nextLink)
	if err != nil {
		return nil, fmt.Errorf("parsing next page link: %w", err)
-- 
2.34.1

[PATCH 2/3] Get all press releases until no next page exists Export this patch

---
 confs/koblenz-press-releases.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/confs/koblenz-press-releases.yml b/confs/koblenz-press-releases.yml
index ce325e2..e840730 100644
--- a/confs/koblenz-press-releases.yml
+++ b/confs/koblenz-press-releases.yml
@@ -56,9 +56,9 @@ selectors:
      end
  nextpage: |-
    link = sel:find(".pagination-next a"):first()
    if (link ~= nil and link ~= "") then
    if (link:attr("href"):match("\/.*"))  then
      print("https://www.koblenz.de" .. link:attr("href"))
    end
  nextpageattr: href
  nextpagecount: 15
  nextpagecount: 25
  sort: ""
-- 
2.34.1

[PATCH 3/3] Store content in variable Export this patch

Directly printing the result of gsub somehow includes a number,
which might be the amount of matched substrings.
This does not happen, when the result is stored in a variable
before printing.
---
 confs/koblenz-press-releases.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/confs/koblenz-press-releases.yml b/confs/koblenz-press-releases.yml
index e840730..1764202 100644
--- a/confs/koblenz-press-releases.yml
+++ b/confs/koblenz-press-releases.yml
@@ -30,7 +30,8 @@ selectors:
        --return error if the request was unsuccesfull
        error(err)
      end
      print(doc:find(".currentPressRelease"):html():gsub("\/pressezentrale","https://www.koblenz.de/pressezentrale"):gsub("https:\/\/www.koblenz.dehttps:\/\/www.koblenz.de", "https://www.koblenz.de"))
      content = doc:find(".currentPressRelease"):first():html():gsub("\/pressezentrale","https://www.koblenz.de/pressezentrale"):gsub("https:\/\/www.koblenz.dehttps:\/\/www.koblenz.de", "https://www.koblenz.de")
      print(content)
    link: |-
      a = sel:find("a")
      itemURL = "https://www.koblenz.de" .. a:attr("href")
-- 
2.34.1