Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
captn3m0 committed Apr 30, 2017
0 parents commit 40a2b27
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
book1/
book2/
book3/
*.html
*.epub
6 changes: 6 additions & 0 deletions Gemfile
@@ -0,0 +1,6 @@
# frozen_string_literal: true
source "https://rubygems.org"

gem 'nokogiri'
gem 'bitly'
gem 'minidown'
37 changes: 37 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,37 @@
GEM
remote: https://rubygems.org/
specs:
bitly (1.1.0)
httparty (>= 0.7.6)
multi_json (~> 1.3)
oauth2 (>= 0.5.0, < 2.0)
faraday (0.11.0)
multipart-post (>= 1.2, < 3)
httparty (0.14.0)
multi_xml (>= 0.5.2)
jwt (1.5.6)
mini_portile2 (2.1.0)
minidown (2.1.1)
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
oauth2 (1.3.1)
faraday (>= 0.8, < 0.12)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
rack (2.0.1)

PLATFORMS
ruby

DEPENDENCIES
bitly
minidown
nokogiri

BUNDLED WITH
1.14.6
4 changes: 4 additions & 0 deletions book1.xml
@@ -0,0 +1,4 @@
<dc:title id="epub-title-1">Magic Muggle: Book 1</dc:title>
<dc:date>2015-11-27</dc:date>
<dc:language>en-US</dc:language>
<dc:creator id="epub-creator-2" opf:role="trl">Doomchicken7</dc:creator>
4 changes: 4 additions & 0 deletions book2.xml
@@ -0,0 +1,4 @@
<dc:title id="epub-title-1">Magic Muggle: Book 2</dc:title>
<dc:date>2016-08-29</dc:date>
<dc:language>en-US</dc:language>
<dc:creator id="epub-creator-2" opf:role="trl">Doomchicken7</dc:creator>
3 changes: 3 additions & 0 deletions book3.xml
@@ -0,0 +1,3 @@
<dc:title id="epub-title-1">Magic Muggle: Book 3</dc:title>
<dc:language>en-US</dc:language>
<dc:creator id="epub-creator-2" opf:role="trl">Doomchicken7</dc:creator>
48 changes: 48 additions & 0 deletions contents.yml
@@ -0,0 +1,48 @@
# Everything in this list is picked up from the sidebar
book1:
- 2dpOlGC
- 2ciOmwg
- 2ckrs8S
- 2c4fl1z
- 2ccMZmQ
- 2cwQ27z
- 2ccMeKu
- 2coBGpB
- 2c8xU2R
- 2cRFxwf
- 2cPOx6q
- 2c2DyA8
- 2cBVmFh
- 2cnBuDt
- 2cFBwaK
- 2cRGVPC
- 2cnCiII
- 2cRGYLi
- 2cFCy6Q

book2:
- 2cnC702
- 2cnCrvy
- 2cFDdFa
- 2c2B7O6
- 2cwQUt2
- 2cFCUdt
- 2cwyh9y
- 2ccNOfl
- 2cwylGx
- 2coDXke
- 2ciPxMr
- 2cwze1D
- 2cwRUNx
- 2c4fwda
- 2cRGDYO
- 2c8xMjS
- 2ccOSQI
- 2c8y8qQ
- 2c8ybTy
- 2c8yM7L
- 2bZuADX
- 2cNAzR5

book3:
- 2cehkgU
23 changes: 23 additions & 0 deletions download.rb
@@ -0,0 +1,23 @@
require 'fileutils'
require 'yaml'
require 'bitly'

Bitly.configure do |config|
config.api_version = 3
config.access_token = ENV['BITLY_KEY']
end
config = YAML.load(File.read 'contents.yml')

for i, book in config
FileUtils.mkdir_p(i)
chapter_index = 1
puts "Book Index: #{i}"
for link in book
unless File.exists? "#{i}/#{chapter_index}.json"
puts "Chapter #{chapter_index} downloading from #{link}"
json_path = Bitly.client.expand(link).long_url + '.json'
`wget --no-clobber "#{json_path}" --output-document "#{i}/#{chapter_index}.json" -o /dev/null`
end
chapter_index += 1
end
end
39 changes: 39 additions & 0 deletions render.rb
@@ -0,0 +1,39 @@
require 'fileutils'
require 'nokogiri'
require 'yaml'
require 'net/http'
require 'pp'
require 'json'
require 'minidown'

config = YAML.load(File.read 'contents.yml')

for i, book in config
chapter = 1
puts "Book Index: #{i}"
html = ''
for link in book

file = "#{i}/#{chapter}.json"
if File.exists? file
json = JSON.parse File.read file
post = json[0]['data']['children'][0]['data']
md = post['selftext']
title = post['title']
html += "<h1>#{title}</h1>"
html += Minidown.render md
end
chapter += 1
end

File.open("#{i}.html", 'w') { |file| file.write(html) }
puts "[html] Generated HTML file for #{i}"
`pandoc -S -o #{i}.epub --epub-metadata=#{i}.xml #{i}.html`
end
# Convert it to epub
# `pandoc -S -o Hoshruba.epub --epub-metadata=metadata.xml --epub-cover-image=cover.jpg Hoshruba.html`
# puts "[epub] Generated EPUB file"

# # Convert epub to a mobi
# `ebook-convert Hoshruba.epub Hoshruba.mobi`
# puts "[mobi] Generated MOBI file"

0 comments on commit 40a2b27

Please sign in to comment.