epub_book 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cover.jpg +0 -0
- data/epub_book.gemspec +41 -0
- data/exe/create_book +24 -0
- data/lib/epub_book/book.rb +180 -0
- data/lib/epub_book/mailer.rb +35 -0
- data/lib/epub_book/version.rb +3 -0
- data/lib/epub_book.rb +50 -0
- data/tsxc.ttf +0 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c4f9c77699e87a2ac6c7b0786d351a0bcbd9535
|
4
|
+
data.tar.gz: 1bc2d4207776f01c4a6270b488318e158fde7ec2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ac14a008b66a8120ff1969940762b982881deb74c5cfa4f240e85880e964541d56259954ec1072f643dacd8bc3789188829335f2602bea7bcca43c2320388a6
|
7
|
+
data.tar.gz: 055a6f5f4f861449dccc03e26b1ff1b998e6ced413975bea86d70cad9f36d4b2e6c59593dbdedbe1b48dd76f3bec0ba7fdf8ba6851f2f5331238b9b3441ac7be
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at qmliu@pearlinpalm.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 qmliu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# EpubBook
|
2
|
+
|
3
|
+
EpubBook is a epub generator which wrap EeePub, handle internal book by nokkogiri, you can create epub book from internal book in shell and send the generated epub book to your email.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'epub_book'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install epub_book
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Setting
|
24
|
+
```ruby
|
25
|
+
#smtp setting
|
26
|
+
EpubBook.configure do |config|
|
27
|
+
config.mail_address = 'smtp.example.com'
|
28
|
+
config.mail_user_name = 'ex@example.com'
|
29
|
+
config.mail_password = 'password'
|
30
|
+
config.mail_from = 'yourmail@example.com'
|
31
|
+
end
|
32
|
+
```
|
33
|
+
Or use a ./default_setting.yml file have following content
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
smtp_config:
|
37
|
+
mail_from: smpt_from@example.com
|
38
|
+
mail_subject: mail subject
|
39
|
+
mail_body: 'your content '
|
40
|
+
mail_address: smtp.example.com
|
41
|
+
mail_port: 25
|
42
|
+
mail_user_name: smpt_mail@example.com
|
43
|
+
mail_password: smpt_pwd
|
44
|
+
|
45
|
+
book:
|
46
|
+
limit: 10
|
47
|
+
cover_css: '.pic_txt_list .pic img'
|
48
|
+
description_css: '.box p.description'
|
49
|
+
title_css: '.pic_txt_list h3 span'
|
50
|
+
index_item_css: 'ul.list li.c3 a'
|
51
|
+
body_css: '.wrapper #content'
|
52
|
+
creator: 'user name'
|
53
|
+
path: '/'
|
54
|
+
mail_to: 'yourmail@example.com'
|
55
|
+
book_url: http://www.quanben5.com/n/bubushenglian/xiaoshuo.html
|
56
|
+
bookname: bbsl
|
57
|
+
```
|
58
|
+
Create book
|
59
|
+
```ruby
|
60
|
+
EpubBook.create_book(book_url,bookname) do |book|
|
61
|
+
book.cover_css = '.pic_txt_list .pic img'
|
62
|
+
book.description_css = '.box p.description'
|
63
|
+
book.title_css = '.pic_txt_list h3 span'
|
64
|
+
book.index_item_css = 'ul.list li.c3 a'
|
65
|
+
book.body_css = '.wrapper #content'
|
66
|
+
book.creator = 'javy_liu'
|
67
|
+
book.path = '/home/oswap/ruby_test/epub_book/'
|
68
|
+
book.mail_to = ''
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
## Parameter specification
|
73
|
+
```ruby
|
74
|
+
book_url(required): internal book index page url (this page may include the description or cover)
|
75
|
+
bookname(optional): created book file name, if not set ,it will use the Base64.url_encode(book_url)[-10,-2]
|
76
|
+
```
|
77
|
+
|
78
|
+
|
79
|
+
## Block parameter specification
|
80
|
+
```ruby
|
81
|
+
book.cover_css #book cover image css path
|
82
|
+
book.description_css #book description css path
|
83
|
+
book.title_css #book title css path
|
84
|
+
book.index_item_css #book catalog item css path
|
85
|
+
book.body_css #book content css path
|
86
|
+
book.creator #epub creator
|
87
|
+
book.path #epub book save path
|
88
|
+
book.mail_to #if your want send by email when epub created, set this to your email
|
89
|
+
```
|
90
|
+
## Perform `create_book` in your terminal
|
91
|
+
```bash
|
92
|
+
create_book
|
93
|
+
```
|
94
|
+
## Development
|
95
|
+
|
96
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
97
|
+
|
98
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/epub_book. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
103
|
+
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
108
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "epub_book"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
#require "irb"
|
14
|
+
#IRB.start
|
data/bin/setup
ADDED
data/cover.jpg
ADDED
Binary file
|
data/epub_book.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'epub_book/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "epub_book"
|
8
|
+
spec.version = EpubBook::VERSION
|
9
|
+
spec.authors = ["qmliu"]
|
10
|
+
spec.email = ["javy_liu@163.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{create epub from a book index url and mail to you.}
|
13
|
+
spec.description = %q{create epub from a book index url and mail to you. by setting a default_setting.yml you can use it in shell. }
|
14
|
+
spec.homepage = "https://githubs.com/javyliu/epub_book"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency 'nokogiri','~> 1.6.8'
|
31
|
+
spec.add_dependency 'eeepub'
|
32
|
+
spec.add_dependency 'zip-zip'
|
33
|
+
spec.add_dependency 'mail'
|
34
|
+
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
spec.add_development_dependency "pry"
|
40
|
+
spec.add_development_dependency "pry-doc"
|
41
|
+
end
|
data/exe/create_book
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "epub_book"
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
# use like
|
8
|
+
# bin/create_book http://www.quanben5.com/n/jinyiyexing/xiaoshuo.html bookname
|
9
|
+
url,bookname = ARGV
|
10
|
+
|
11
|
+
default_config = YAML.load(File.open('./default_setting.yml'))
|
12
|
+
#smtp setting
|
13
|
+
EpubBook.configure do |config|
|
14
|
+
default_config['smtp_config'].each_pair do |key,value|
|
15
|
+
config.send("#{key}=",value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
EpubBook.create_book(url || default_config['book_url'],bookname || default_config['bookname']) do |book|
|
20
|
+
default_config['book'].each_pair do |key,value|
|
21
|
+
book.send("#{key}=",value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'eeepub'
|
4
|
+
require 'base64'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
#index_url 书目录地址
|
8
|
+
#title_css 书名css路径
|
9
|
+
#index_item_css 目录页列表项目,默认 ul.list3>li>a
|
10
|
+
#body_css 内容css, 默认 .articlebody
|
11
|
+
#limit 用于测试时使用,得到页面的页数
|
12
|
+
#item_attr 目录页item获取属性 默认为 'href'
|
13
|
+
#page_css 分页css路径
|
14
|
+
#page_attr 分页链接地址属性
|
15
|
+
#path 存储目录
|
16
|
+
#user_agent 访问代理
|
17
|
+
#referer 访问原地址
|
18
|
+
#creator 责任人
|
19
|
+
|
20
|
+
module EpubBook
|
21
|
+
class Book
|
22
|
+
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36"
|
23
|
+
Referer = "http://www.baidu.com/"
|
24
|
+
attr_accessor :title_css, :index_item_css, :body_css, :limit, :item_attr, :page_css, :page_attr,:cover
|
25
|
+
attr_accessor :cover_css, :description_css,:path,:user_agent,:referer,:creator,:mail_to
|
26
|
+
|
27
|
+
|
28
|
+
Reg = /<script.*?>.*?<\/script>/m
|
29
|
+
|
30
|
+
def initialize(index_url )
|
31
|
+
@index_url = index_url
|
32
|
+
@user_agent = UserAgent
|
33
|
+
@referer = Referer
|
34
|
+
@folder_name = Base64.urlsafe_encode64(index_url)[-10..-3]
|
35
|
+
@creator = 'javy_liu'
|
36
|
+
@title_css = '.wrapper h1.title1'
|
37
|
+
@index_item_css = 'ul.list3>li>a'
|
38
|
+
@cover = 'cover.jpg'
|
39
|
+
@body_css = '.articlebody'
|
40
|
+
@item_attr = "href"
|
41
|
+
yield self if block_given?
|
42
|
+
@book_path = File.join((@path || `pwd`), @folder_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def link_host
|
47
|
+
@link_host ||= @index_url[/\A(http:\/\/.*?)\/\w+/,1]
|
48
|
+
end
|
49
|
+
|
50
|
+
def book
|
51
|
+
@book ||= test(?s,File.join(@book_path,'index.yml')) ? YAML.load(File.open(File.join(@book_path,'index.yml'))) : ({files: []})
|
52
|
+
end
|
53
|
+
|
54
|
+
def save_book
|
55
|
+
File.open(File.join(@book_path,'index.yml' ),'w') do |f|
|
56
|
+
f.write(@book.to_yaml)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
#创建书本
|
62
|
+
def generate_book(book_name=nil)
|
63
|
+
Dir.mkdir(@book_path) unless test(?d,@book_path)
|
64
|
+
#获取epub源数据
|
65
|
+
fetch_book
|
66
|
+
if !@cover_css && @cover
|
67
|
+
generate_cover = <<-eof
|
68
|
+
convert #{File.expand_path("../../../#{@cover}",__FILE__)} -font tsxc.ttf -gravity center -fill red -pointsize 16 -draw "text 0,0 '#{book[:title]}'" #{File.join(@book_path,@cover)}
|
69
|
+
eof
|
70
|
+
system(generate_cover)
|
71
|
+
end
|
72
|
+
|
73
|
+
epub = EeePub.make
|
74
|
+
|
75
|
+
epub.title book[:title]
|
76
|
+
epub.creator @creator
|
77
|
+
epub.publisher @creator
|
78
|
+
epub.date Time.now
|
79
|
+
epub.identifier "http://javy_liu.com/book/#{@folder_name}", :scheme => 'URL'
|
80
|
+
epub.uid "http://javy_liu.com/book/#{@folder_name}"
|
81
|
+
epub.cover @cover
|
82
|
+
epub.subject book[:title]
|
83
|
+
epub.description book[:description] if book[:description]
|
84
|
+
|
85
|
+
book[:files] = book[:files][0...limit] if limit
|
86
|
+
|
87
|
+
epub.files book[:files].map{|item| File.join(@book_path,item[:content])}.push(File.join(@book_path,@cover))
|
88
|
+
epub.nav book[:files]
|
89
|
+
|
90
|
+
|
91
|
+
epub_file = File.join(@book_path,"#{book_name || @folder_name}.epub")
|
92
|
+
|
93
|
+
epub.save(epub_file)
|
94
|
+
|
95
|
+
#send mail
|
96
|
+
puts mail_to
|
97
|
+
if mail_to
|
98
|
+
mailer = Mailer.new
|
99
|
+
mailer.to = mail_to
|
100
|
+
mailer.add_file epub_file
|
101
|
+
|
102
|
+
mailer.send_mail
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def fetch_index(url=nil)
|
109
|
+
url ||= @index_url
|
110
|
+
doc = Nokogiri::HTML(open(URI.encode(url),"User-Agent" => @user_agent ,'Referer'=> @referer).read)
|
111
|
+
#generate index.yml
|
112
|
+
|
113
|
+
book[:title] ||= doc.css(@title_css).text.strip
|
114
|
+
|
115
|
+
if @cover_css && !book[:cover]
|
116
|
+
cover_url = doc.css(@cover_css).attr("src").to_s
|
117
|
+
cover_url = link_host + cover_url unless cover_url.start_with?("http")
|
118
|
+
system("curl #{cover_url} -o #{File.join(@book_path,@cover)} ")
|
119
|
+
book[:cover] = File.join(@book_path,@cover)
|
120
|
+
end
|
121
|
+
|
122
|
+
if @description_css && !book[:description]
|
123
|
+
book[:description] = doc.css(@description_css).text
|
124
|
+
end
|
125
|
+
|
126
|
+
doc.css(@index_item_css).each do |item|
|
127
|
+
_href = URI.encode(item.attr(@item_attr).to_s)
|
128
|
+
_href = link_host + _href unless _href.start_with?("http")
|
129
|
+
book[:files] << {label: item.text, url: _href}
|
130
|
+
end
|
131
|
+
|
132
|
+
#如果有分页
|
133
|
+
if @page_css && @page_attr
|
134
|
+
if next_page = doc.css(@page_css).attr(@page_attr).to_s
|
135
|
+
fetch_index(next_page)
|
136
|
+
else
|
137
|
+
return
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
book[:files].each_with_index{|item,index| item[:content] = "#{index}.html"}
|
142
|
+
|
143
|
+
#保存书目
|
144
|
+
save_book
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
def fetch_book
|
149
|
+
#重新得到书目,如果不存在或重新索引的话
|
150
|
+
fetch_index if !test(?s,File.join(@book_path,'index.yml'))
|
151
|
+
book[:files].each_with_index do |item,index|
|
152
|
+
break if limit && index >= limit
|
153
|
+
|
154
|
+
content_path = File.join(@book_path,item[:content])
|
155
|
+
|
156
|
+
#如果文件存在且长度不为0则获取下一个
|
157
|
+
next if test(?s,content_path)
|
158
|
+
|
159
|
+
begin
|
160
|
+
doc_file = Nokogiri::HTML(open(item[:url],"User-Agent" => @user_agent,'Referer'=> @referer).read)
|
161
|
+
|
162
|
+
File.open(content_path,'w') do |f|
|
163
|
+
f.write("<h3>#{item[:label]}</h3>")
|
164
|
+
f.write(doc_file.css(@body_css).to_s.gsub(Reg,''))
|
165
|
+
end
|
166
|
+
|
167
|
+
puts item[:label]
|
168
|
+
|
169
|
+
rescue Exception => e
|
170
|
+
puts e.message
|
171
|
+
puts e.backtrace.inspect
|
172
|
+
next
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'mail'
|
2
|
+
|
3
|
+
module EpubBook
|
4
|
+
class Mailer
|
5
|
+
extend Forwardable
|
6
|
+
::Mail.defaults do
|
7
|
+
delivery_method :smtp, {
|
8
|
+
:address => EpubBook.config.mail_address,
|
9
|
+
:port => EpubBook.config.mail_port,
|
10
|
+
:user_name => EpubBook.config.mail_user_name,
|
11
|
+
:password => EpubBook.config.mail_password,
|
12
|
+
:authentication => :plain,
|
13
|
+
:enable_starttls_auto => true
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def_delegators :@mailer, :from,:from=,:to,:to=,:subject,:subject=,:body,:body=,:add_file
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@mailer = Mail.new do
|
23
|
+
from EpubBook.config.mail_from
|
24
|
+
subject EpubBook.config.mail_subject
|
25
|
+
body EpubBook.config.mail_body
|
26
|
+
#add_file File.join(File.dirname(__FILE__),'bbsl.epub')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def send_mail
|
31
|
+
@mailer.deliver!
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/epub_book.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "epub_book/version"
|
2
|
+
require 'epub_book/book'
|
3
|
+
|
4
|
+
module EpubBook
|
5
|
+
# Your code goes here...
|
6
|
+
autoload :Book, "epub_book/book"
|
7
|
+
autoload :Mailer, "epub_book/mailer"
|
8
|
+
|
9
|
+
def self.create_book(url,bookname=nil,&block)
|
10
|
+
epub_book = Book.new(url,&block)
|
11
|
+
#do |book|
|
12
|
+
# book.limit = 5
|
13
|
+
# book.cover_css = '.pic_txt_list .pic img'
|
14
|
+
# book.description_css = '.box p.description'
|
15
|
+
# book.title_css = '.pic_txt_list h3 span'
|
16
|
+
# book.index_item_css = 'ul.list li.c3 a'
|
17
|
+
# book.body_css = '.wrapper #content'
|
18
|
+
# book.creator = 'javy_liu'
|
19
|
+
# book.path = '/home/oswap/ruby_test/epub_book/'
|
20
|
+
# book.user_agent = ''
|
21
|
+
# book.referer = ''
|
22
|
+
# book.mail_to = 'javy_liu@163.com'
|
23
|
+
#end
|
24
|
+
#epub_book.fetch_index
|
25
|
+
epub_book.generate_book(bookname)
|
26
|
+
end
|
27
|
+
|
28
|
+
Config = Struct.new(:mail_from,:mail_subject,:mail_body,:mail_address,:mail_port,:mail_user_name,:mail_password)
|
29
|
+
class Config
|
30
|
+
include Singleton
|
31
|
+
def initialize
|
32
|
+
self.mail_subject = 'epub 电子书'
|
33
|
+
self.mail_body = "您创建的电子书见附件\n"
|
34
|
+
self.mail_port = 25
|
35
|
+
#mail_from
|
36
|
+
#mail_address
|
37
|
+
#mail_user_name
|
38
|
+
#mail_password
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def self.config
|
44
|
+
Config.instance
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.configure
|
48
|
+
yield config
|
49
|
+
end
|
50
|
+
end
|
data/tsxc.ttf
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: epub_book
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- qmliu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.8
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eeepub
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: zip-zip
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mail
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.12'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-doc
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: 'create epub from a book index url and mail to you. by setting a default_setting.yml
|
140
|
+
you can use it in shell. '
|
141
|
+
email:
|
142
|
+
- javy_liu@163.com
|
143
|
+
executables:
|
144
|
+
- create_book
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- ".rspec"
|
150
|
+
- ".travis.yml"
|
151
|
+
- CODE_OF_CONDUCT.md
|
152
|
+
- Gemfile
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- bin/console
|
157
|
+
- bin/setup
|
158
|
+
- cover.jpg
|
159
|
+
- epub_book.gemspec
|
160
|
+
- exe/create_book
|
161
|
+
- lib/epub_book.rb
|
162
|
+
- lib/epub_book/book.rb
|
163
|
+
- lib/epub_book/mailer.rb
|
164
|
+
- lib/epub_book/version.rb
|
165
|
+
- tsxc.ttf
|
166
|
+
homepage: https://githubs.com/javyliu/epub_book
|
167
|
+
licenses:
|
168
|
+
- MIT
|
169
|
+
metadata:
|
170
|
+
allowed_push_host: https://rubygems.org
|
171
|
+
post_install_message:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
174
|
+
- lib
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
requirements: []
|
186
|
+
rubyforge_project:
|
187
|
+
rubygems_version: 2.4.8
|
188
|
+
signing_key:
|
189
|
+
specification_version: 4
|
190
|
+
summary: create epub from a book index url and mail to you.
|
191
|
+
test_files: []
|