-
-
Save warmbreeze/4f5cd64f7d1918d87fae1ee697eaca2e to your computer and use it in GitHub Desktop.
Free Programming Ebooks - O'Reilly Media. Codeship free ebooks here - https://bit.ly/2oQ0knQ
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
| # This script generates links for downloading free books from O'Reilly site (http://www.oreilly.com/programming/free) | |
| # Requirements | |
| # ruby | |
| # httparty, nokogiri (gem install httparty nokogiri --no-ri --no-rdoc) | |
| # Execute | |
| # ruby script.rb > books.md | |
| require 'httparty' | |
| require 'nokogiri' | |
| require 'uri' | |
| URL = 'http://www.oreilly.com/' | |
| THEMES = ['programming', 'iot', 'data', 'webops', 'web-platform', 'security', 'business'] | |
| FORMATS = ['pdf', 'epub', 'mobi'] | |
| def theme_url(theme) | |
| URL + theme + '/' + 'free/' | |
| end | |
| def download_url(book, fmt) | |
| theme_url(book[:theme]) + 'files/' + book[:file_name] + '.' + fmt | |
| end | |
| def get_book_info(link) | |
| splitted_url = URI(link.attributes['href'].value).path.split('/') | |
| { | |
| theme: splitted_url[1], | |
| title: link.attributes['title'].value, | |
| file_name: splitted_url.last.split('.').first | |
| } | |
| end | |
| def books(theme_url) | |
| Nokogiri.HTML(HTTParty.get(theme_url).body) | |
| .css("section .product-row a") | |
| .map { |link| get_book_info(link) } | |
| end | |
| def main | |
| THEMES.each do |t| | |
| puts "# From theme: #{t.capitalize}" | |
| books(theme_url(t)).each do |book| | |
| puts "### #{book[:title]}" | |
| FORMATS.each { |fmt| puts "[#{fmt}](#{download_url(book, fmt)}) " } | |
| end | |
| end | |
| end | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment