Created
January 23, 2015 02:10
-
-
Save ZucchiniZe/e6dd3ff4d137252131de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'capybara' | |
| require 'capybara/poltergeist' | |
| require 'awesome_print' | |
| Capybara.app_host = 'http://alexb.ninja/blog' | |
| Capybara.current_driver = :poltergeist | |
| Capybara.run_server = false | |
| module API | |
| class << self | |
| include Capybara::DSL | |
| def posts | |
| visit '/' | |
| posts = [] | |
| all('.posts li').each_with_index do |post,i| | |
| posts[i] = { | |
| :title => post.find('p[itemprop]').text, | |
| :url => post.find('a')['href'], | |
| :time => post.find('time').text, | |
| :datetime => post.find('time')['datetime'] | |
| } | |
| end | |
| posts.each do |post| | |
| visit post[:url][5..post[:url].length] | |
| post[:body] = find('div[itemprop=articleBody]').text | |
| post[:wordcount] = post[:body].split.size | |
| post[:readingtime] = (post[:wordcount] / 180).ceil | |
| end | |
| end | |
| end | |
| end | |
| ap API::posts, options = {:indent => 2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment