2011-03-27 22:56:15 +02:00
|
|
|
module PagesHelper
|
2014-02-17 18:05:39 +01:00
|
|
|
def blog_entries
|
|
|
|
blog = ''
|
|
|
|
begin
|
|
|
|
Timeout::timeout(5) 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
|
|
|
|
2014-02-17 18:05:39 +01: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
|
2014-02-17 18:05:39 +01:00
|
|
|
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
|
|
|
|