~ghost08/ratt

e72ca2d0814eaaf1bb008739037966674f70a4ca — Daniel Hecker 6 months ago ffb7117
fix: koblenz-press-releases.lua, selectors.go

This commit fixes the currently broken press releases.
Some selectors got updated, some code moved around and some
cleanup for the content html.

This has also some small code changes for selectors.go,
as the configuration for the next page was not loaded before.
2 files changed, 20 insertions(+), 17 deletions(-)

M confs/koblenz-press-releases.lua
M selectors.go
M confs/koblenz-press-releases.lua => confs/koblenz-press-releases.lua +17 -17
@@ 30,40 30,40 @@ ratt.add(
					"https://www.koblenz.de/pressezentrale"):gsub(
					"https:\\/\\/www.koblenz.dehttps:\\/\\/www.koblenz.de",
					"https://www.koblenz.de"
				)
				return content
			end,
        ):gsub(
          "<h2.*</h2>",
          ""
        ):gsub(
          "<p[^>]+>",
          "<p>"
        )
        return content
      end,
			link = "a",
			linkattr = "href",
			created = function(sel, _)
				local time = sel:find("time"):first():text()
				-- return current date, if the time field contains time instead of date
				if time:match(".*:.*") then
					print(os.date("%d.%m.%Y"))
					return
					return os.date("%d.%m.%Y")
				end
				return time
			end,
			createdformat = "02.01.2006",
			description = "div.article-teaser__teaser p",
			description = "p.article-teaser__teaser",
			image = function(sel, _)
				local img = sel:find("img"):first():attr("data-src")
				if img ~= "" then
					-- prepend host if needed
					if not (img:match("https*:\\/\\/.*")) then
					if not (img:match("https*://.*")) then
						img = "https://www.koblenz.de" .. img
					end
					return img
				end
			end,
			nextpage = function(sel, _)
				local link = sel:find(".pagination-next a"):first()
				if (link:attr("href"):match("\\/.*")) then
					return "https://www.koblenz.de" .. link:attr("href")
				end
			end,
			nextpageattr = "href",
			nextpagecount = 25
		}
	}
    },
    nextpage = ".pagination-next a",
    nextpageattr = "href",
    nextpagecount = 3
  }
)

M selectors.go => selectors.go +3 -0
@@ 62,6 62,9 @@ func (r *Ratt) NewSelectorsFromLua(sels *lua.LTable) *Selectors {
		HTTPSettings: httpsettings.FromLua(sels.RawGetString("httpsettings")),
		Feed:         feedFromLua(sels.RawGetString("feed")),
		Item:         itemFromLua(sels.RawGetString("item")),
		NextPage:     sels.RawGetString("nextpage"),
		NextPageAttr: lua.LVAsString(sels.RawGetString("nextpageattr")),
		NextPageCount: int(lua.LVAsNumber(sels.RawGetString("nextpagecount"))),
	}
	return s
}