forked from captn3m0/cosmere-books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wok-reread.rb
107 lines (96 loc) · 4.35 KB
/
wok-reread.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: true
require 'date'
require 'fileutils'
require 'nokogiri'
require_relative './methods'
FileUtils.mkdir_p('wok')
BASE = 'https://www.tor.com/'
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/'
]
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 = ''
for i in 1..(links.length)
complete_html = Nokogiri::HTML(open("wok/#{i}.html"))
page = complete_html.css('.entry-content')
title = complete_html.css('.entry-title>a').inner_html
# Removes all UK cover images
page.css('.alignleft').remove
ending = false
page.children.each do |e|
ending = true if e.class?('squib') || e.class?('post-end-spacer')
e.remove if ending
end
html += "<h1>#{title}</h1>"
html += page.inner_html
url = BASE + links[i - 1]
html += "<p>Visit <a href='#{url}'>tor.com</a> for discussion.</p>"
end
File.open('books/wok-reread.html', 'w') { |file| file.write(html) }
puts '[html] Generated HTML file'
generate('wok-reread', :all)