diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..f49590f --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,50 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2017-09-17 09:34:31 +0530 using RuboCop version 0.50.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +Metrics/AbcSize: + Max: 16 + +# Offense count: 8 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 80 + AllowHeredoc: true + AllowURI: true + URISchemes: + - https + - http + IgnoredPatterns: + - \` + +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 22 + +# Offense count: 1 +Metrics/PerceivedComplexity: + Max: 10 + +# Offense count: 2 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'wok-reread.rb' + - 'wor-reread.rb' + +# Offense count: 5 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: for, each +Style/For: + Exclude: + - 'oathbringer.rb' + - 'wok-reread.rb' + - 'wor-reread.rb' diff --git a/README.md b/README.md index a0762c8..075e619 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Scripts to generate books from the [Cosmere]() using various public sources. Cur 1. Oathbringer (Serialized till Chapter 32) 2. Way of Kings Reread +3. Words of Radiance Reread For obvious reasons, the converted ebooks are not part of this repo. You must download and run the script on your own machine to generate the copies. diff --git a/methods.rb b/methods.rb index 1e9c3fe..1ececcc 100644 --- a/methods.rb +++ b/methods.rb @@ -1,50 +1,78 @@ +module Nokogiri + module XML + # Patch to add class? + class Node + def class?(*classes) + present = false + if self.attribute('class') + present = true + classes.each do |klass| + present &&= self['class'].include? klass + end + end + present + end + end + end +end + # https://stackoverflow.com/a/42533209/368328 def command?(name) [name, - *ENV['PATH'].split(File::PATH_SEPARATOR).map {|p| File.join(p, name)} - ].find {|f| File.executable?(f)} + *ENV['PATH'].split(File::PATH_SEPARATOR) + .map { |p| File.join(p, name) }] + .find { |f| File.executable?(f) } end def commands?(commands) - commands.map {|c| command? c} + commands.map { |c| command? c } end def format_match(format) [:all, format].include? format end - -def generate(name, format=:all) - if command? 'pandoc' and format_match(:epub) +def gen_epub(name, _format) + if command?('pandoc') && format_match(:epub) # Convert it to epub `pandoc -S -o books/#{name}.epub --epub-metadata=metadata/#{name}.xml --epub-cover-image=covers/#{name}.jpg books/#{name}.html` - puts "[epub] Generated EPUB file" + puts '[epub] Generated EPUB file' else puts "[error] Can't generate EPUB without pandoc" end +end - if command? 'ebook-convert' and format_match(:mobi) +def gen_mobi(name, _format) + if command?('ebook-convert') && format_match(:mobi) # Convert epub to a mobi `ebook-convert books/#{name}.epub books/#{name}.mobi` - puts "[mobi] Generated MOBI file" + puts '[mobi] Generated MOBI file' else puts "[error] Can't generate MOBI without ebook-convert" end +end - if commands? ['pandoc', 'convert', 'wkhtmltopdf', 'pdftk'] and format_match(:pdf) +def gen_pdf(name, _format) + if commands?(%w[pandoc convert wkhtmltopdf pdftk]) && format_match(:pdf) # Generate PDF as well # First, lets make a better css version of the html - `pandoc books/#{name}.html -s -c style.css -o books/#{name}_pdf.html` - puts "[pdf] Generated html for pdf" + `pandoc books/#{name}.html -s -c ../style.css -o books/#{name}_pdf.html` + puts '[pdf] Generated html for pdf' # Print the pdf_html file to pdf - `wkhtmltopdf #{name}_pdf.html books/#{name}-nocover.pdf` - puts "[pdf] Generated PDF without cover" + `wkhtmltopdf books/#{name}_pdf.html books/#{name}-nocover.pdf` + puts '[pdf] Generated PDF without cover' # Join the cover and pdf together `pdftk covers/#{name}.pdf books/#{name}-nocover.pdf cat output books/#{name}.pdf` - puts "[pdf] Generated PDF file" + puts '[pdf] Generated PDF file' else - puts "[error] Please check README for PDF dependencies" + puts '[error] Please check README for PDF dependencies' end end + +def generate(name, _format = :all) + gen_epub(name, _format) + gen_mobi(name, _format) + gen_pdf(name, _format) +end diff --git a/oathbringer.rb b/oathbringer.rb index d99dd41..bd982a4 100644 --- a/oathbringer.rb +++ b/oathbringer.rb @@ -2,15 +2,15 @@ require 'fileutils' require 'nokogiri' require_relative './methods' -FileUtils.mkdir_p("oathbringer") +FileUtils.mkdir_p('oathbringer') -BASE = 'https://www.tor.com/2017/' +BASE = 'https://www.tor.com/2017/'.freeze links = [ - '08/22/oathbringer-brandon-sanderson-prologue/', - '08/29/oathbringer-brandon-sanderson-chapter-1-3/', - '09/05/oathbringer-by-brandon-sanderson-chapters-4-6/', - '09/12/oathbringer-by-brandon-sanderson-chapters-7-9/' + '08/22/oathbringer-brandon-sanderson-prologue/', + '08/29/oathbringer-brandon-sanderson-chapter-1-3/', + '09/05/oathbringer-by-brandon-sanderson-chapters-4-6/', + '09/12/oathbringer-by-brandon-sanderson-chapters-7-9/' ] links.last.split('/') @@ -22,43 +22,39 @@ episode = 1 -for link in links - url = BASE + link - puts "Download #{url}" - if !File.exists? "oathbringer/#{episode}.html" - `wget --no-clobber "#{url}" --output-document "oathbringer/#{episode}.html" -o /dev/null` - end - episode +=1 +links.each do |link| + url = BASE + link + puts "Download #{url}" + unless File.exist? "oathbringer/#{episode}.html" + `wget --no-clobber "#{url}" --output-document "oathbringer/#{episode}.html" -o /dev/null` + end + episode += 1 end # Now we have all the files -html = "" +html = '' for i in 1..(links.length) page = Nokogiri::HTML(open("oathbringer/#{i}.html")).css('.entry-content') start = ending = false page.children.each do |e| - if e.name == 'h3' - e.name = 'h1' - start = true - end + if e.name == 'h3' + e.name = 'h1' + start = true + end - if e.attribute('class') and e['class'].include? 'frontmatter' and start - ending = true - end + ending = true if e.class?('frontmatter') && start - if !start or ending - e.remove - end + e.remove if !start || ending end html += page.inner_html - url = links[i-1] + url = links[i - 1] html += "

Visit tor.com for discussion.

" end -html += "

~fin\~
Next 3 chapters out on #{next_date.to_s}

" +html += "

~fin\~
Next 3 chapters out on #{next_date}

" -File.open("books/Oathbringer.html", 'w') { |file| file.write(html) } -puts "[html] Generated HTML file" +File.open('books/Oathbringer.html', 'w') { |file| file.write(html) } +puts '[html] Generated HTML file' -generate("Oathbringer", :all) +generate('Oathbringer', :all) diff --git a/wok-reread.rb b/wok-reread.rb index 21f052a..d9a4903 100644 --- a/wok-reread.rb +++ b/wok-reread.rb @@ -3,83 +3,83 @@ require 'nokogiri' require_relative './methods' -FileUtils.mkdir_p("wok") +FileUtils.mkdir_p('wok') -BASE = 'https://www.tor.com/' +BASE = 'https://www.tor.com/'.freeze links = [ - "2013/03/14/the-way-of-kings-reread-introduction/", - "2013/03/28/the-way-of-kings-reread-prelude-to-the-stormlight-archive/", - "2013/04/04/the-way-of-kings-reread-prologue-to-kill/", - "2013/04/11/the-way-of-kings-reread-chapter-1-and-chapter-2/", - "2013/04/18/the-way-of-kings-reread-chapters-3-and-4/", - "2013/04/25/the-way-of-kings-reread-chapters-5-and-6/", - "2013/05/02/the-way-of-kings-reread-chapter-7-and-chapter-8/", - "2013/05/09/the-way-of-kings-reread-chapters-9-and-10/", - "2013/05/16/the-way-of-kings-reread-chapter-11/", - "2013/05/23/the-way-of-kings-reread-interludes-1-2-3/", - "2013/05/30/the-way-of-kings-reread-chapter-12/", - "2013/06/06/the-way-of-kings-reread-chapters-13-and-14/", - "2013/06/13/the-way-of-kings-reread-chapter-15/", - "2013/06/20/the-way-of-kings-reread-chapters-16-and-17/", - "2013/06/27/the-way-of-kings-reread-chapter-18/", - "2013/07/11/the-way-of-kings-reread-chapters-19-and-20/", - "2013/07/18/the-way-of-kings-reread-chapters-21-and-22/", - "2013/07/25/the-way-of-kings-reread-chapter-23-and-24/", - "2013/08/01/the-way-of-kings-reread-chapters-25-and-26/", - "2013/08/08/the-way-of-kings-reread-chapters-27-and-28/", - "2013/08/15/the-way-of-kings-reread-epigraphs-to-part-two/", - "2013/08/22/the-way-of-kings-reread-interludes-i-4-i-5-and-i-6/", - "2013/09/05/the-way-of-kings-reread-chapter-29/", - "2013/09/12/the-way-of-kings-reread-chapter-30/", - "2013/09/19/the-way-of-kings-reread-chapters-31-and-32/", - "2013/09/26/the-way-of-kings-reread-chapter-33/", - "2013/10/03/the-way-of-kings-reread-chapters-34-35-and-36/", - "2013/10/10/the-way-of-kings-reread-chapter-37/", - "2013/10/17/the-way-of-kings-reread-chapters-38-and-39/", - "2013/10/24/the-way-of-kings-reread-chapters-40-and-41/", - "2013/10/31/the-way-of-kings-reread-chapters-42-and-43/", - "2013/11/07/the-way-of-kings-reread-chapter-44/", - "2013/11/14/the-way-of-kings-reread-chapter-45/", - "2013/11/21/the-way-of-kings-reread-chapter-46/", - "2013/12/05/the-way-of-kings-reread-chapter-47/", - "2013/12/12/the-way-of-kings-reread-chapter-48/", - "2013/12/19/the-way-of-kings-reread-chapter-49/", - "2014/01/02/the-way-of-kings-reread-chapters-50-and-51/", - "2014/01/09/the-way-of-kings-reread-interludes-i-7-i-8-and-i-9/", - "2014/01/16/the-way-of-kings-reread-chapter-52/", - "2014/01/23/the-way-of-kings-reread-chapters-53-and-54/", - "2014/01/30/the-way-of-kings-reread-chapter-55/", - "2014/02/06/the-way-of-kings-reread-chapter-56/", - "2014/02/13/the-way-of-kings-reread-chapter-57/", - "2014/02/20/the-way-of-kings-reread-chapter-58/", - "2014/02/27/the-way-of-kings-reread-chapter-59/", - "2014/03/20/the-way-of-kings-reread-chapters-60-and-61/", - "2014/03/27/the-way-of-kings-reread-chapters-62-and-63/", - "2014/04/03/the-way-of-kings-reread-chapters-64-and-65/", - "2014/04/10/the-way-of-kings-reread-chapters-66-and-67/", - "2014/04/17/the-way-of-kings-reread-chapter-68/", - "2014/04/24/the-way-of-kings-reread-chapter-69/", - "2014/05/01/the-way-of-kings-reread-chapters-70-and-71/", - "2014/05/08/the-way-of-kings-reread-chapters-72-and-73/", - "2014/05/15/the-way-of-kings-reread-chapters-74-and-75/", - "2014/05/22/the-way-of-kings-reread-epilogue-and-all-that-comes-after/", - "2014/06/10/brandon-sanderson-answers-your-questions-about-the-way-of-kings/" + '2013/03/14/the-way-of-kings-reread-introduction/', + '2013/03/28/the-way-of-kings-reread-prelude-to-the-stormlight-archive/', + '2013/04/04/the-way-of-kings-reread-prologue-to-kill/', + '2013/04/11/the-way-of-kings-reread-chapter-1-and-chapter-2/', + '2013/04/18/the-way-of-kings-reread-chapters-3-and-4/', + '2013/04/25/the-way-of-kings-reread-chapters-5-and-6/', + '2013/05/02/the-way-of-kings-reread-chapter-7-and-chapter-8/', + '2013/05/09/the-way-of-kings-reread-chapters-9-and-10/', + '2013/05/16/the-way-of-kings-reread-chapter-11/', + '2013/05/23/the-way-of-kings-reread-interludes-1-2-3/', + '2013/05/30/the-way-of-kings-reread-chapter-12/', + '2013/06/06/the-way-of-kings-reread-chapters-13-and-14/', + '2013/06/13/the-way-of-kings-reread-chapter-15/', + '2013/06/20/the-way-of-kings-reread-chapters-16-and-17/', + '2013/06/27/the-way-of-kings-reread-chapter-18/', + '2013/07/11/the-way-of-kings-reread-chapters-19-and-20/', + '2013/07/18/the-way-of-kings-reread-chapters-21-and-22/', + '2013/07/25/the-way-of-kings-reread-chapter-23-and-24/', + '2013/08/01/the-way-of-kings-reread-chapters-25-and-26/', + '2013/08/08/the-way-of-kings-reread-chapters-27-and-28/', + '2013/08/15/the-way-of-kings-reread-epigraphs-to-part-two/', + '2013/08/22/the-way-of-kings-reread-interludes-i-4-i-5-and-i-6/', + '2013/09/05/the-way-of-kings-reread-chapter-29/', + '2013/09/12/the-way-of-kings-reread-chapter-30/', + '2013/09/19/the-way-of-kings-reread-chapters-31-and-32/', + '2013/09/26/the-way-of-kings-reread-chapter-33/', + '2013/10/03/the-way-of-kings-reread-chapters-34-35-and-36/', + '2013/10/10/the-way-of-kings-reread-chapter-37/', + '2013/10/17/the-way-of-kings-reread-chapters-38-and-39/', + '2013/10/24/the-way-of-kings-reread-chapters-40-and-41/', + '2013/10/31/the-way-of-kings-reread-chapters-42-and-43/', + '2013/11/07/the-way-of-kings-reread-chapter-44/', + '2013/11/14/the-way-of-kings-reread-chapter-45/', + '2013/11/21/the-way-of-kings-reread-chapter-46/', + '2013/12/05/the-way-of-kings-reread-chapter-47/', + '2013/12/12/the-way-of-kings-reread-chapter-48/', + '2013/12/19/the-way-of-kings-reread-chapter-49/', + '2014/01/02/the-way-of-kings-reread-chapters-50-and-51/', + '2014/01/09/the-way-of-kings-reread-interludes-i-7-i-8-and-i-9/', + '2014/01/16/the-way-of-kings-reread-chapter-52/', + '2014/01/23/the-way-of-kings-reread-chapters-53-and-54/', + '2014/01/30/the-way-of-kings-reread-chapter-55/', + '2014/02/06/the-way-of-kings-reread-chapter-56/', + '2014/02/13/the-way-of-kings-reread-chapter-57/', + '2014/02/20/the-way-of-kings-reread-chapter-58/', + '2014/02/27/the-way-of-kings-reread-chapter-59/', + '2014/03/20/the-way-of-kings-reread-chapters-60-and-61/', + '2014/03/27/the-way-of-kings-reread-chapters-62-and-63/', + '2014/04/03/the-way-of-kings-reread-chapters-64-and-65/', + '2014/04/10/the-way-of-kings-reread-chapters-66-and-67/', + '2014/04/17/the-way-of-kings-reread-chapter-68/', + '2014/04/24/the-way-of-kings-reread-chapter-69/', + '2014/05/01/the-way-of-kings-reread-chapters-70-and-71/', + '2014/05/08/the-way-of-kings-reread-chapters-72-and-73/', + '2014/05/15/the-way-of-kings-reread-chapters-74-and-75/', + '2014/05/22/the-way-of-kings-reread-epilogue-and-all-that-comes-after/', + '2014/06/10/brandon-sanderson-answers-your-questions-about-the-way-of-kings/' ] episode = 1 -for link in links - url = BASE + link - puts "Download #{url}" - if !File.exists? "wok/#{episode}.html" - `wget --no-clobber "#{url}" --output-document "wok/#{episode}.html" -o /dev/null` - end - episode +=1 +links.each do |link| + url = BASE + link + puts "Download #{url}" + unless File.exist? "wok/#{episode}.html" + `wget --no-clobber "#{url}" --output-document "wok/#{episode}.html" -o /dev/null` + end + episode += 1 end # Now we have all the files -html = "" +html = '' for i in 1..(links.length) complete_html = Nokogiri::HTML(open("wok/#{i}.html")) page = complete_html.css('.entry-content') @@ -88,24 +88,18 @@ page.css('.alignleft').remove ending = false page.children.each do |e| - - if e.attribute('class') and (e['class'].include? 'squib' or e['class'].include? 'post-end-spacer') - ending = true - end - - if ending - e.remove - end + ending = true if e.class?('squib') || e.class?('post-end-spacer') + e.remove if ending end html += "

#{title}

" html += page.inner_html - url = links[i-1] + url = links[i - 1] html += "

Visit tor.com for discussion.

" end -File.open("books/wok-reread.html", 'w') { |file| file.write(html) } -puts "[html] Generated HTML file" +File.open('books/wok-reread.html', 'w') { |file| file.write(html) } +puts '[html] Generated HTML file' -generate("wok-reread", :all) +generate('wok-reread', :all) diff --git a/wor-reread.rb b/wor-reread.rb index 47bc721..f872644 100644 --- a/wor-reread.rb +++ b/wor-reread.rb @@ -3,155 +3,149 @@ require 'nokogiri' require_relative './methods' -FileUtils.mkdir_p("wor") +FileUtils.mkdir_p('wor') -BASE = 'https://www.tor.com' +BASE = 'https://www.tor.com'.freeze links = [ - "/2014/06/12/introducing-the-words-of-radiance-reread/", - "/2014/06/12/words-of-radiance-reread-prologue/", - "/2014/06/19/words-of-radiance-reread-chapter-1/", - "/2014/06/26/words-of-radiance-reread-chapter-2/", - "/2014/07/03/words-of-radiance-reread-chapter-three/", - "/2014/07/10/words-of-radiance-reread-chapter-4/", - "/2014/07/17/words-of-radiance-reread-chapter-5/", - "/2014/07/24/words-of-radiance-reread-chapter-6/", - "/2014/07/31/words-of-radiance-reread-chapter-7/", - "/2014/08/07/words-of-radiance-reread-chapter-8/", - "/2014/08/14/words-of-radiance-reread-chapter-9/", - "/2014/08/21/words-of-radiance-reread-chapter-10/", - "/2014/08/28/words-of-radiance-reread-chapter-11/", - "/2014/09/04/words-of-radiance-reread-chapter-12/", - "/2014/09/11/words-of-radiance-reread-interlude-1/", - "/2014/09/18/words-of-radiance-reread-interlude-2/", - "/2014/09/25/words-of-radiance-reread-interlude-3/", - "/2014/10/02/words-of-radiance-reread-interlude-4/", - "/2014/10/09/words-of-radiance-reread-chapter-13/", - "/2014/10/16/words-of-radiance-reread-chapter-14/", - "/2014/10/23/words-of-radiance-reread-chapter-15/", - "/2014/10/30/words-of-radiance-reread-chapter-16/", - "/2014/11/06/words-of-radiance-reread-chapter-17/", - "/2014/11/13/words-of-radiance-reread-chapter-18/", - "/2014/11/20/words-of-radiance-reread-chapter-19/", - "/2014/12/04/words-of-radiance-reread-chapter-20/", - "/2014/12/11/words-of-radiance-reread-chapter-21/", - "/2014/12/18/words-of-radiance-reread-chapter-22/", - "/2015/01/08/words-of-radiance-reread-chapter-23/", - "/2015/01/15/words-of-radiance-reread-chapter-24/", - "/2015/01/22/words-of-radiance-reread-chapter-25/", - "/2015/01/29/words-of-radiance-reread-chapter-26/", - "/2015/02/05/words-of-radiance-reread-chapter-27/", - "/2015/02/12/words-of-radiance-reread-chapter-28/", - "/2015/02/19/words-of-radiance-reread-chapter-29/", - "/2015/02/26/words-of-radiance-reread-chapter-30/", - "/2015/03/05/words-of-radiance-reread-chapter-31/", - "/2015/03/12/words-of-radiance-reread-chapter-32/", - "/2015/03/19/words-of-radiance-reread-chapter-33/", - "/2015/03/26/words-of-radiance-reread-chapter-34/", - "/2015/04/02/words-of-radiance-reread-part-2-epigraphs/", - "/2015/04/09/words-of-radiance-reread-interludes-5-and-6/", - "/2015/04/16/words-of-radiance-reread-interludes-7-and-8/", - "/2015/04/23/words-of-radiance-reread-chapter-35/", - "/2015/04/30/words-of-radiance-reread-chapter-36/", - "/2015/05/07/words-of-radiance-reread-chapter-37/", - "/2015/05/14/words-of-radiance-reread-chapter-38/", - "/2015/05/21/words-of-radiance-reread-chapter-39/", - "/2015/05/28/words-of-radiance-reread-chapter-40/", - "/2015/06/04/words-of-radiance-reread-chapter-41/", - "/2015/06/11/words-of-radiance-reread-chapter-42/", - "/2015/06/18/words-of-radiance-reread-chapter-43/", - "/2015/06/25/words-of-radiance-reread-chapter-44/", - "/2015/07/02/words-of-radiance-reread-chapter-45/", - "/2015/07/09/words-of-radiance-reread-chapter-46/", - "/2015/07/23/words-of-radiance-reread-chapter-47/", - "/2015/07/30/words-of-radiance-reread-chapter-48/", - "/2015/08/06/words-of-radiance-reread-chapter-49/", - "/2015/08/13/words-of-radiance-reread-chapter-50/", - "/2015/08/20/words-of-radiance-reread-chapter-51/", - "/2015/08/27/words-of-radiance-reread-chapter-52/", - "/2015/09/03/words-of-radiance-reread-chapter-53/", - "/2015/09/10/words-of-radiance-reread-chapter-54/", - "/2015/09/17/words-of-radiance-reread-chapter-55/", - "/2015/09/24/words-of-radiance-reread-chapter-56/", - "/2015/10/01/words-of-radiance-reread-chapter-57/", - "/2015/10/08/words-of-radiance-reread-chapter-58/", - "/2015/10/15/words-of-radiance-reread-interlude-9/", - "/2015/10/22/words-of-radiance-reread-interlude-10/", - "/2015/10/29/words-of-radiance-reread-interlude-11/", - "/2015/11/05/words-of-radiance-reread-chapter-59/", - "/2015/11/12/words-of-radiance-reread-chapter-60/", - "/2015/11/19/words-of-radiance-reread-chapter-61/", - "/2015/12/03/words-of-radiance-reread-chapter-62/", - "/2015/12/10/words-of-radiance-reread-chapter-63/", - "/2015/12/17/words-of-radiance-reread-chapter-64/", - "/2016/01/07/words-of-radiance-reread-chapter-65/", - "/2016/01/14/words-of-radiance-reread-chapter-66/", - "/2016/01/21/words-of-radiance-reread-chapter-67/", - "/2016/01/28/words-of-radiance-reread-chapter-68/", - "/2016/02/04/words-of-radiance-reread-chapter-69/", - "/2016/02/11/words-of-radiance-reread-chapter-70/", - "/2016/02/18/words-of-radiance-reread-chapter-71/", - "/2016/02/25/words-of-radiance-reread-chapter-72/", - "/2016/03/03/words-of-radiance-reread-chapter-73/", - "/2016/03/10/words-of-radiance-reread-chapter-74/", - "/2016/03/17/words-of-radiance-reread-chapter-75/", - "/2016/03/24/words-of-radiance-reread-part-4-epigraphs/", - "/2016/03/31/words-of-radiance-reread-interludes-12-and-13/", - "/2016/04/07/words-of-radiance-reread-interlude-14/", - "/2016/04/14/words-of-radiance-reread-chapter-76/", - "/2016/04/21/words-of-radiance-reread-chapter-77/", - "/2016/04/28/words-of-radiance-reread-chapter-78/", - "/2016/05/05/words-of-radiance-reread-chapter-79/", - "/2016/05/12/words-of-radiance-reread-chapter-80/", - "/2016/05/19/words-of-radiance-reread-chapter-81/", - "/2016/05/26/words-of-radiance-reread-chapter-82/", - "/2016/06/02/words-of-radiance-reread-chapter-83/", - "/2016/06/09/words-of-radiance-reread-chapter-84/", - "/2016/06/16/words-of-radiance-reread-chapter-85/", - "/2016/06/23/words-of-radiance-reread-chapter-86/", - "/2016/06/30/words-of-radiance-reread-chapter-87/", - "/2016/07/14/words-of-radiance-reread-chapter-88/", - "/2016/07/28/words-of-radiance-reread-chapter-89/", - "/2016/08/04/words-of-radiance-reread-epilogue-and-what-comes-next/" + '/2014/06/12/introducing-the-words-of-radiance-reread/', + '/2014/06/12/words-of-radiance-reread-prologue/', + '/2014/06/19/words-of-radiance-reread-chapter-1/', + '/2014/06/26/words-of-radiance-reread-chapter-2/', + '/2014/07/03/words-of-radiance-reread-chapter-three/', + '/2014/07/10/words-of-radiance-reread-chapter-4/', + '/2014/07/17/words-of-radiance-reread-chapter-5/', + '/2014/07/24/words-of-radiance-reread-chapter-6/', + '/2014/07/31/words-of-radiance-reread-chapter-7/', + '/2014/08/07/words-of-radiance-reread-chapter-8/', + '/2014/08/14/words-of-radiance-reread-chapter-9/', + '/2014/08/21/words-of-radiance-reread-chapter-10/', + '/2014/08/28/words-of-radiance-reread-chapter-11/', + '/2014/09/04/words-of-radiance-reread-chapter-12/', + '/2014/09/11/words-of-radiance-reread-interlude-1/', + '/2014/09/18/words-of-radiance-reread-interlude-2/', + '/2014/09/25/words-of-radiance-reread-interlude-3/', + '/2014/10/02/words-of-radiance-reread-interlude-4/', + '/2014/10/09/words-of-radiance-reread-chapter-13/', + '/2014/10/16/words-of-radiance-reread-chapter-14/', + '/2014/10/23/words-of-radiance-reread-chapter-15/', + '/2014/10/30/words-of-radiance-reread-chapter-16/', + '/2014/11/06/words-of-radiance-reread-chapter-17/', + '/2014/11/13/words-of-radiance-reread-chapter-18/', + '/2014/11/20/words-of-radiance-reread-chapter-19/', + '/2014/12/04/words-of-radiance-reread-chapter-20/', + '/2014/12/11/words-of-radiance-reread-chapter-21/', + '/2014/12/18/words-of-radiance-reread-chapter-22/', + '/2015/01/08/words-of-radiance-reread-chapter-23/', + '/2015/01/15/words-of-radiance-reread-chapter-24/', + '/2015/01/22/words-of-radiance-reread-chapter-25/', + '/2015/01/29/words-of-radiance-reread-chapter-26/', + '/2015/02/05/words-of-radiance-reread-chapter-27/', + '/2015/02/12/words-of-radiance-reread-chapter-28/', + '/2015/02/19/words-of-radiance-reread-chapter-29/', + '/2015/02/26/words-of-radiance-reread-chapter-30/', + '/2015/03/05/words-of-radiance-reread-chapter-31/', + '/2015/03/12/words-of-radiance-reread-chapter-32/', + '/2015/03/19/words-of-radiance-reread-chapter-33/', + '/2015/03/26/words-of-radiance-reread-chapter-34/', + '/2015/04/02/words-of-radiance-reread-part-2-epigraphs/', + '/2015/04/09/words-of-radiance-reread-interludes-5-and-6/', + '/2015/04/16/words-of-radiance-reread-interludes-7-and-8/', + '/2015/04/23/words-of-radiance-reread-chapter-35/', + '/2015/04/30/words-of-radiance-reread-chapter-36/', + '/2015/05/07/words-of-radiance-reread-chapter-37/', + '/2015/05/14/words-of-radiance-reread-chapter-38/', + '/2015/05/21/words-of-radiance-reread-chapter-39/', + '/2015/05/28/words-of-radiance-reread-chapter-40/', + '/2015/06/04/words-of-radiance-reread-chapter-41/', + '/2015/06/11/words-of-radiance-reread-chapter-42/', + '/2015/06/18/words-of-radiance-reread-chapter-43/', + '/2015/06/25/words-of-radiance-reread-chapter-44/', + '/2015/07/02/words-of-radiance-reread-chapter-45/', + '/2015/07/09/words-of-radiance-reread-chapter-46/', + '/2015/07/23/words-of-radiance-reread-chapter-47/', + '/2015/07/30/words-of-radiance-reread-chapter-48/', + '/2015/08/06/words-of-radiance-reread-chapter-49/', + '/2015/08/13/words-of-radiance-reread-chapter-50/', + '/2015/08/20/words-of-radiance-reread-chapter-51/', + '/2015/08/27/words-of-radiance-reread-chapter-52/', + '/2015/09/03/words-of-radiance-reread-chapter-53/', + '/2015/09/10/words-of-radiance-reread-chapter-54/', + '/2015/09/17/words-of-radiance-reread-chapter-55/', + '/2015/09/24/words-of-radiance-reread-chapter-56/', + '/2015/10/01/words-of-radiance-reread-chapter-57/', + '/2015/10/08/words-of-radiance-reread-chapter-58/', + '/2015/10/15/words-of-radiance-reread-interlude-9/', + '/2015/10/22/words-of-radiance-reread-interlude-10/', + '/2015/10/29/words-of-radiance-reread-interlude-11/', + '/2015/11/05/words-of-radiance-reread-chapter-59/', + '/2015/11/12/words-of-radiance-reread-chapter-60/', + '/2015/11/19/words-of-radiance-reread-chapter-61/', + '/2015/12/03/words-of-radiance-reread-chapter-62/', + '/2015/12/10/words-of-radiance-reread-chapter-63/', + '/2015/12/17/words-of-radiance-reread-chapter-64/', + '/2016/01/07/words-of-radiance-reread-chapter-65/', + '/2016/01/14/words-of-radiance-reread-chapter-66/', + '/2016/01/21/words-of-radiance-reread-chapter-67/', + '/2016/01/28/words-of-radiance-reread-chapter-68/', + '/2016/02/04/words-of-radiance-reread-chapter-69/', + '/2016/02/11/words-of-radiance-reread-chapter-70/', + '/2016/02/18/words-of-radiance-reread-chapter-71/', + '/2016/02/25/words-of-radiance-reread-chapter-72/', + '/2016/03/03/words-of-radiance-reread-chapter-73/', + '/2016/03/10/words-of-radiance-reread-chapter-74/', + '/2016/03/17/words-of-radiance-reread-chapter-75/', + '/2016/03/24/words-of-radiance-reread-part-4-epigraphs/', + '/2016/03/31/words-of-radiance-reread-interludes-12-and-13/', + '/2016/04/07/words-of-radiance-reread-interlude-14/', + '/2016/04/14/words-of-radiance-reread-chapter-76/', + '/2016/04/21/words-of-radiance-reread-chapter-77/', + '/2016/04/28/words-of-radiance-reread-chapter-78/', + '/2016/05/05/words-of-radiance-reread-chapter-79/', + '/2016/05/12/words-of-radiance-reread-chapter-80/', + '/2016/05/19/words-of-radiance-reread-chapter-81/', + '/2016/05/26/words-of-radiance-reread-chapter-82/', + '/2016/06/02/words-of-radiance-reread-chapter-83/', + '/2016/06/09/words-of-radiance-reread-chapter-84/', + '/2016/06/16/words-of-radiance-reread-chapter-85/', + '/2016/06/23/words-of-radiance-reread-chapter-86/', + '/2016/06/30/words-of-radiance-reread-chapter-87/', + '/2016/07/14/words-of-radiance-reread-chapter-88/', + '/2016/07/28/words-of-radiance-reread-chapter-89/', + '/2016/08/04/words-of-radiance-reread-epilogue-and-what-comes-next/' ] episode = 1 -for link in links - url = BASE + link - puts "Download #{url}" - if !File.exists? "wor/#{episode}.html" - `wget --no-clobber "#{url}" --output-document "wor/#{episode}.html" -o /dev/null` - end - episode +=1 +links.each do |link| + url = BASE + link + puts "Download #{url}" + unless File.exist? "wor/#{episode}.html" + `wget --no-clobber "#{url}" --output-document "wor/#{episode}.html" -o /dev/null` + end + episode += 1 end # Now we have all the files -html = "" +html = '' for i in 1..(links.length) complete_html = Nokogiri::HTML(open("wor/#{i}.html")) page = complete_html.css('.entry-content') title = complete_html.css('.entry-title>a').inner_html ending = false page.children.each do |e| - - if e.attribute('class') and (e['class'].include? 'squib' or e['class'].include? 'post-end-spacer') - ending = true - end - - if ending - e.remove - end + ending = true if e.class?('squib') || e.class?('post-end-spacer') + e.remove if ending end html += "

#{title}

" html += page.inner_html - url = links[i-1] + url = links[i - 1] html += "

Visit tor.com for discussion.

" end -File.open("books/wor-reread.html", 'w') { |file| file.write(html) } -puts "[html] Generated HTML file" +File.open('books/wor-reread.html', 'w') { |file| file.write(html) } +puts '[html] Generated HTML file' -generate("wor-reread", :all) +generate('wor-reread', :all)