brandeins 0.2.2 → 0.3.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -1
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +47 -21
- data/NOTES.md +6 -0
- data/Rakefile +15 -8
- data/bin/brandeins +3 -1
- data/brandeins.gemspec +0 -1
- data/lib/brandeins.rb +3 -5
- data/lib/brandeins/cli.rb +46 -34
- data/lib/brandeins/config.rb +18 -0
- data/lib/brandeins/kiosk.rb +100 -0
- data/lib/brandeins/merger/external/base.rb +16 -6
- data/lib/brandeins/merger/pdf_tools.rb +3 -6
- data/lib/brandeins/pages/archive.rb +91 -0
- data/lib/brandeins/pages/article.rb +37 -0
- data/lib/brandeins/pages/cover.rb +67 -0
- data/lib/brandeins/pages/magazine.rb +149 -0
- data/lib/brandeins/utils/cli_option_parser.rb +40 -0
- data/lib/brandeins/utils/cli_output.rb +100 -0
- data/lib/brandeins/utils/fetcher.rb +115 -0
- data/lib/brandeins/utils/merger.rb +41 -0
- data/lib/brandeins/version.rb +1 -1
- data/rubocop-todo.yml +141 -0
- data/spec/lib/brandeins/kiosk_spec.rb +66 -0
- data/spec/lib/brandeins/pages/archive_spec.rb +40 -0
- data/spec/lib/brandeins/pages/article_spec.rb +23 -0
- data/spec/lib/brandeins/pages/magazine_spec.rb +91 -0
- data/spec/lib/brandeins/utils/fetcher_spec.rb +8 -0
- data/spec/lib/brandeins_spec.rb +19 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/capture_stdout.rb +12 -0
- data/spec/support/fixtures/archive.html +2365 -0
- data/spec/support/fixtures/artikel-masskonfektion-aus-plastik.html +254 -0
- data/spec/support/fixtures/artikel-schauspieler-daenemark.html +247 -0
- data/{test_support → spec/support}/fixtures/cover.jpg +0 -0
- data/spec/support/fixtures/editorial.html +236 -0
- data/spec/support/fixtures/just-a.pdf +0 -0
- data/spec/support/fixtures/magazine-1-2013.html +242 -0
- data/spec/support/fixtures/magazine-cover-fallback.html +1610 -0
- data/spec/support/fixtures/magazine-with-cover.html +1416 -0
- metadata +68 -61
- data/.rvmrc +0 -48
- data/lib/brandeins/downloader.rb +0 -111
- data/lib/brandeins/errors.rb +0 -5
- data/lib/brandeins/parser/archive_site.rb +0 -54
- data/lib/brandeins/parser/article_site.rb +0 -26
- data/lib/brandeins/parser/magazine_site.rb +0 -49
- data/lib/brandeins/setup.rb +0 -38
- data/specs/brandeins_spec.rb +0 -52
- data/specs/spec_helper.rb +0 -1
- data/test/brandeins_test.rb +0 -65
- data/test/helper.rb +0 -1
- data/test_support/capture_stdout.rb +0 -12
- data/test_support/fixtures/brandeins_archiv.html +0 -50
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: c1c4cc751ae449333a24d1127535da306b200154
|
|
4
|
+
data.tar.gz: d2a62acfbdef5f2c7f563edc342579bd156523e2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5120d2ceaa37925d19fa43ca96cf8f5709526c5d7cc368cb19ea1e2c5a520de90670cd5d6c81987919b321967199358621b835a8f0e8c8fdb075d70623f5a9ad
|
|
7
|
+
data.tar.gz: f2a313a749fcd7cebb93822bace5242af17018ae64825e4f1c9d065ec13ec607633138cf6cdff29efe79bbdf3e663c93e985eef53e00d3b47c27ad96a5ee1185
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.0.0-p247
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
source "http://rubygems.org"
|
|
2
2
|
|
|
3
3
|
group :test do
|
|
4
|
-
|
|
5
|
-
gem 'minitest'
|
|
6
|
-
end
|
|
4
|
+
gem 'rspec'
|
|
7
5
|
gem 'webmock'
|
|
8
|
-
gem '
|
|
6
|
+
gem 'rubocop'
|
|
9
7
|
end
|
|
10
8
|
|
|
9
|
+
group :debug do
|
|
10
|
+
if RUBY_VERSION.split('.').first.to_i > 1
|
|
11
|
+
gem 'byebug'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
11
14
|
|
|
12
15
|
gemspec
|
data/Gemfile.lock
CHANGED
|
@@ -1,47 +1,73 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
brandeins (0.
|
|
4
|
+
brandeins (0.3.0.pre)
|
|
5
5
|
nokogiri
|
|
6
6
|
prawn
|
|
7
7
|
rake
|
|
8
|
-
thor
|
|
9
8
|
|
|
10
9
|
GEM
|
|
11
10
|
remote: http://rubygems.org/
|
|
12
11
|
specs:
|
|
13
12
|
Ascii85 (1.0.2)
|
|
14
|
-
addressable (2.3.
|
|
13
|
+
addressable (2.3.5)
|
|
14
|
+
afm (0.2.0)
|
|
15
|
+
ast (1.1.0)
|
|
16
|
+
byebug (2.5.0)
|
|
17
|
+
columnize (~> 0.3.6)
|
|
18
|
+
debugger-linecache (~> 1.2.0)
|
|
15
19
|
columnize (0.3.6)
|
|
16
|
-
crack (0.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
crack (0.4.1)
|
|
21
|
+
safe_yaml (~> 0.9.0)
|
|
22
|
+
debugger-linecache (1.2.0)
|
|
23
|
+
diff-lcs (1.2.5)
|
|
24
|
+
hashery (2.1.1)
|
|
25
|
+
mini_portile (0.5.2)
|
|
26
|
+
nokogiri (1.6.1)
|
|
27
|
+
mini_portile (~> 0.5.0)
|
|
28
|
+
parser (2.0.0)
|
|
29
|
+
ast (~> 1.1)
|
|
30
|
+
slop (~> 3.4, >= 3.4.5)
|
|
31
|
+
pdf-reader (1.3.3)
|
|
27
32
|
Ascii85 (~> 1.0.0)
|
|
33
|
+
afm (~> 0.2.0)
|
|
28
34
|
hashery (~> 2.0)
|
|
29
35
|
ruby-rc4
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
ttfunk
|
|
37
|
+
powerpack (0.0.9)
|
|
38
|
+
prawn (0.13.0)
|
|
39
|
+
afm
|
|
40
|
+
pdf-reader (~> 1.2)
|
|
41
|
+
ruby-rc4
|
|
32
42
|
ttfunk (~> 1.0.3)
|
|
33
|
-
|
|
43
|
+
rainbow (1.1.4)
|
|
44
|
+
rake (10.1.0)
|
|
45
|
+
rspec (2.14.1)
|
|
46
|
+
rspec-core (~> 2.14.0)
|
|
47
|
+
rspec-expectations (~> 2.14.0)
|
|
48
|
+
rspec-mocks (~> 2.14.0)
|
|
49
|
+
rspec-core (2.14.7)
|
|
50
|
+
rspec-expectations (2.14.4)
|
|
51
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
52
|
+
rspec-mocks (2.14.4)
|
|
53
|
+
rubocop (0.15.0)
|
|
54
|
+
parser (~> 2.0)
|
|
55
|
+
powerpack (~> 0.0.6)
|
|
56
|
+
rainbow (>= 1.1.4)
|
|
34
57
|
ruby-rc4 (0.1.5)
|
|
35
|
-
|
|
58
|
+
safe_yaml (0.9.7)
|
|
59
|
+
slop (3.4.7)
|
|
36
60
|
ttfunk (1.0.3)
|
|
37
|
-
webmock (1.
|
|
61
|
+
webmock (1.16.1)
|
|
38
62
|
addressable (>= 2.2.7)
|
|
39
|
-
crack (>= 0.
|
|
63
|
+
crack (>= 0.3.2)
|
|
40
64
|
|
|
41
65
|
PLATFORMS
|
|
42
66
|
ruby
|
|
43
67
|
|
|
44
68
|
DEPENDENCIES
|
|
45
69
|
brandeins!
|
|
46
|
-
|
|
70
|
+
byebug
|
|
71
|
+
rspec
|
|
72
|
+
rubocop
|
|
47
73
|
webmock
|
data/NOTES.md
ADDED
data/Rakefile
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
require 'bundler/gem_tasks'
|
|
2
2
|
require 'rake/testtask'
|
|
3
|
+
require 'rubocop/rake_task'
|
|
4
|
+
require 'rspec/autorun'
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
Rubocop::RakeTask.new
|
|
7
|
+
|
|
8
|
+
Rake::TestTask.new(:spec) do |t|
|
|
9
|
+
t.pattern = 'spec/lib/**/*_spec.rb'
|
|
10
|
+
t.verbose = true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
task :load_version_file do
|
|
14
|
+
require_relative './lib/brandeins/version'
|
|
7
15
|
end
|
|
8
16
|
|
|
9
|
-
task :
|
|
10
|
-
|
|
17
|
+
task install: [ :load_version_file ] do
|
|
18
|
+
require_relative './lib/brandeins/version'
|
|
11
19
|
sh "gem install ./pkg/brandeins-#{BrandEins::VERSION}.gem"
|
|
12
20
|
end
|
|
13
21
|
|
|
14
|
-
task
|
|
15
|
-
require './lib/brandeins/version'
|
|
22
|
+
task install: [ :load_version_file, :build ] do
|
|
16
23
|
sh "gem push ./pkg/brandeins-#{BrandEins::VERSION}.gem"
|
|
17
24
|
end
|
|
18
25
|
|
|
@@ -32,4 +39,4 @@ rule /^version:bump:(major|minor|patch)/ do |t|
|
|
|
32
39
|
sh "git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
|
|
33
40
|
end
|
|
34
41
|
|
|
35
|
-
task :
|
|
42
|
+
task default: :spec
|
data/bin/brandeins
CHANGED
data/brandeins.gemspec
CHANGED
|
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
s.description = %q{BrandEins gem offers a download command to download a specific or all volumes. Use `brandeins help` to find out more about it}
|
|
13
13
|
|
|
14
14
|
s.add_dependency "rake"
|
|
15
|
-
s.add_dependency "thor"
|
|
16
15
|
s.add_dependency "nokogiri"
|
|
17
16
|
s.add_dependency "prawn"
|
|
18
17
|
|
data/lib/brandeins.rb
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
require 'brandeins/setup'
|
|
7
|
-
require 'brandeins/cli'
|
|
3
|
+
require_relative 'brandeins/version'
|
|
4
|
+
require_relative 'brandeins/config'
|
|
5
|
+
require_relative 'brandeins/kiosk'
|
|
8
6
|
|
|
9
7
|
module BrandEins; end
|
data/lib/brandeins/cli.rb
CHANGED
|
@@ -1,47 +1,59 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'ostruct'
|
|
5
|
+
require 'singleton'
|
|
6
|
+
|
|
7
|
+
require_relative '../brandeins'
|
|
8
|
+
require_relative '../brandeins/utils/cli_option_parser'
|
|
3
9
|
|
|
4
10
|
module BrandEins
|
|
5
|
-
class CLI
|
|
6
|
-
|
|
11
|
+
class CLI
|
|
12
|
+
include Singleton
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
def self.run(args)
|
|
15
|
+
@@args = args
|
|
16
|
+
instance.run
|
|
11
17
|
end
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
else
|
|
31
|
-
downloader.get_magazine year, volume
|
|
32
|
-
end
|
|
19
|
+
def initialize(args = ARGV)
|
|
20
|
+
@args = (@@args || args).dup
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def run
|
|
24
|
+
options = BrandEins::CliOptionParser.parse(@args)
|
|
25
|
+
if options.version
|
|
26
|
+
puts BrandEins::VERSION
|
|
27
|
+
return
|
|
28
|
+
end
|
|
29
|
+
if options.download
|
|
30
|
+
path = options.path
|
|
31
|
+
month = options.month
|
|
32
|
+
year = options.year
|
|
33
|
+
errors = validate_options(options)
|
|
34
|
+
puts errors.join("\n") && return unless error.empty?
|
|
35
|
+
download(path: path, month: month, yeaR: year)
|
|
33
36
|
end
|
|
34
37
|
end
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
def download(path: nil, month: nil, year: nil)
|
|
40
|
+
kiosk = BrandEins::Kiosk.new(path: path)
|
|
41
|
+
kiosk.fetch_magazine(month: month, year: year)
|
|
42
|
+
rescue BrandEins::Utils::Fetcher::ContentNotFetchedError => e
|
|
43
|
+
puts "Download Error: #{e}\n\n"
|
|
44
|
+
puts "#{e.backtrace.join('\n')}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def validate_options
|
|
48
|
+
errors = []
|
|
49
|
+
if !(1..12).include? @options.month
|
|
50
|
+
errors.push("Invalid month: Must be between 1 and 12")
|
|
44
51
|
end
|
|
52
|
+
if !(2000..Time.now.year).include? @options.year
|
|
53
|
+
errors.push("Invalid year: Must be between 2000 and #{Time.now.year}")
|
|
54
|
+
end
|
|
55
|
+
return errors
|
|
45
56
|
end
|
|
57
|
+
|
|
46
58
|
end
|
|
47
59
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'pathname'
|
|
2
|
+
# Access it like:
|
|
3
|
+
# BrandEins::Config['base_uri']
|
|
4
|
+
#
|
|
5
|
+
module BrandEins
|
|
6
|
+
class Config
|
|
7
|
+
BASE_URI = 'http://www.brandeins.de'
|
|
8
|
+
ARCHIVE_URI = BASE_URI + '/archiv.html'
|
|
9
|
+
BASE_PATH = Pathname.new(ENV['HOME']) + '.brandeins'
|
|
10
|
+
CACHE_PATH = BASE_PATH + 'cache'
|
|
11
|
+
TEMP_PATH = BASE_PATH + 'temp'
|
|
12
|
+
CACHE_LIMIT_BYTES = 400 * 1024 ** 2
|
|
13
|
+
|
|
14
|
+
def self.[](name)
|
|
15
|
+
const_get(name.upcase)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'pathname'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
|
|
4
|
+
require_relative 'config'
|
|
5
|
+
require_relative 'utils/fetcher'
|
|
6
|
+
require_relative 'pages/archive'
|
|
7
|
+
require_relative 'pages/archive'
|
|
8
|
+
require_relative 'pages/cover'
|
|
9
|
+
require_relative 'merger/pdf_tools'
|
|
10
|
+
|
|
11
|
+
module BrandEins
|
|
12
|
+
# Usage of
|
|
13
|
+
class Kiosk
|
|
14
|
+
attr_reader :target_path
|
|
15
|
+
|
|
16
|
+
class InvalidPathError < StandardError; end
|
|
17
|
+
|
|
18
|
+
def initialize(opts = {})
|
|
19
|
+
@target_path = opts.fetch(:path) { Pathname.new('.').realpath.to_s }
|
|
20
|
+
raise_if_path_inaccessible
|
|
21
|
+
set_opts_for_cli_output(opts)
|
|
22
|
+
create_directories_if_necessary
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create_directories_if_necessary
|
|
26
|
+
cache_path.mkpath unless cache_path.exist?
|
|
27
|
+
temp_path.mkpath unless temp_path.exist?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def set_opts_for_cli_output(opts)
|
|
31
|
+
cli_output_opts = {}
|
|
32
|
+
cli_output_opts[:debug] = !!opts[:verbose]
|
|
33
|
+
cli.set_options(cli_output_opts)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def raise_if_path_inaccessible
|
|
37
|
+
path = Pathname.new(@target_path)
|
|
38
|
+
if !path.writable?
|
|
39
|
+
raise InvalidPathError, 'Could not access the given path'
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def download_magazine(month: nil, year: nil)
|
|
44
|
+
magazine = fetch_magazine(month: month, year: year)
|
|
45
|
+
cover_pdf_path = download_cover(magazine)
|
|
46
|
+
article_pdf_paths = download_article_pdfs(magazine)
|
|
47
|
+
magazine_pdf_files = article_pdfs.unshift(cover_pdf)
|
|
48
|
+
merge_pdf_files(magazine_pdf_files)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def merge_pdf_files(pdf_files)
|
|
52
|
+
magazine_file_path = magazine_file_path(month: month, year: year)
|
|
53
|
+
merger.merge_pdf_files(pdf_files, magazine_file_path)
|
|
54
|
+
clear_temp_path
|
|
55
|
+
magazine_file_path
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def download_article_pdfs(magazine)
|
|
59
|
+
magazine.save_articles_to(temp_path)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def download_cover(magazine)
|
|
63
|
+
cover = BrandEins::Pages::Cover.new(magazine)
|
|
64
|
+
cover.save_to(temp_path)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def fetch_magazine(month: nil, year: nil)
|
|
68
|
+
archive.magazine_for(month: month, year: year)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def magazine_file_path(month: nil, year: nil)
|
|
72
|
+
Pathname.new(@target_path) + "brandeins-#{month}-#{year}.pdf"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def clear_temp_path
|
|
76
|
+
FileUtils.rm Dir["#{temp_path}/*.pdf"]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def merger
|
|
80
|
+
@merger ||= BrandEins::Merger::PdfTools.get_pdf_tool
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def temp_path
|
|
84
|
+
BrandEins::Config['temp_path']
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def cache_path
|
|
88
|
+
BrandEins::Config['cache_path']
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def archive
|
|
92
|
+
@archive ||= BrandEins::Pages::Archive.new
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def cli
|
|
96
|
+
@cli ||= BrandEins::Utils::CliOutput.instance
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
end
|