You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

5 years ago
require "digest/sha1"
require "open-uri"
require "nokogiri"
require "roda"
module Rzz
class App < Roda
plugin :caching
plugin :json
5 years ago
route do |r|
r.get do
r.is "test-gym" do
url = "https://elemental.medium.com/test-gym/home"
html = URI.open(url).read
doc = Nokogiri::HTML(html)
items = doc.xpath("//a[@data-post-id]").map {|a|
attrs = a.attributes
id = attrs.fetch("data-post-id").value
title = a.xpath("./h3").text
content = a.xpath("./div").text
href = URI(attrs.fetch("href"))
url = "#{href.scheme}://#{href.host}#{href.path}"
{ id: id, title: title, content_text: content, url: url }
}
{
version: "https://jsonfeed.org/version/1",
title: "Test Gym",
home_page_url: url,
feed_url: "#{r.base_url}#{r.path}",
items: items,
}
5 years ago
end
end
end
end
end
if __FILE__ == $0
url = "https://elemental.medium.com/feed"
xml = URI.open(url).read
doc = Nokogiri::XML(xml)
5 years ago
require "pry"
binding.pry
end