Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Direct links to Free Codeship eBooks about Continuous Integration and Delivery, Docker, efficient Software Development, distributed team workflows, and much more.

Free Programming Ebooks - CodeShip

require 'httparty'
require 'nokogiri'
require 'uri'
module CodeshipSite
URL = 'https://resources.codeship.com/ebooks'
end
module CodeshipSite::URLBuilder
def self.download_url(book_filename, fmt)
"https://resources.codeship.com/hubfs/#{book_filename}.#{fmt}"
end
end
module CodeshipSite::Crawler
def self.library
books
end
private
def self.books
divs = Nokogiri.HTML(HTTParty.get(CodeshipSite::URL).body).css('div.hs_cos_wrapper .resourceModule').to_a
divs.reject! {|div| div.text.strip.empty? }
divs.map do |div|
get_book_info(div)
end
end
def self.get_book_info(div)
book = OpenStruct.new(
title: find_title(div),
url: CodeshipSite::URLBuilder.download_url(find_file_name(div), 'pdf')
)
book
end
def self.find_title(div)
title_div = div.css('div.span9.widget-span')
title_div.inner_text.split("\n").reject(&:empty?).first.lstrip
end
def self.find_file_name(div)
img = div.css('div.span3.widget-span img').first.attributes['src'].value
filename = URI.parse(img).path.split('/').last.split('.').first
filename.slice!('_sml')
filename
end
puts
end
def markdown(books)
main_header = "# Free Programming Ebooks - CodeShip \n"
books_list = books.map do |book|
"- ### [#{book.title}](#{book.url})"
end
[main_header, books_list.join("\n")].join("\n")
end
def main
puts markdown(CodeshipSite::Crawler.library)
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment