thingspeak/app/helpers/pages_helper.rb

30 lines
658 B
Ruby
Raw Permalink Normal View History

2011-03-27 22:56:15 +02:00
module PagesHelper
def blog_entries
blog = ''
begin
2014-10-06 17:42:02 +02:00
Timeout.timeout(5, Timeout::Error) do
# get the blog data
blog_url = "http://community.thingspeak.com"
doc = Nokogiri::HTML(open(blog_url, "User-Agent" => "Ruby/#{RUBY_VERSION}").read)
2014-05-09 02:01:41 +02:00
# parse out the html we need
doc.css("img").remove
doc.css("script").remove
doc.css("iframe").remove
doc.css("div.post").each_with_index do |d, i|
# only show 3 posts
if (i < 3)
blog += d.css("h2").to_s
blog += d.css("div.entry").to_s
2014-05-09 02:01:41 +02:00
blog += "<hr>" if i != 2
end
end
end
rescue Timeout::Error
rescue
end
blog
end
2011-03-27 22:56:15 +02:00
end
2014-05-09 02:01:41 +02:00