sq 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/sq +28 -0
- data/lib/sq.rb +53 -0
- data/tests/tests.rb +28 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 13322e186f26b4bfd9d0d549d9e431d11e5eb204
|
4
|
+
data.tar.gz: 27fef1a017cedea1b8f624fa69933197b7914801
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9323f2d65d1dae55a2d0ecceb979f983ef62584759dbcadc4a7c6cd63df1e1091f042c3f748df794ad9fa40e60aa0bbbcbb6c93d4b6e6815e00788c9117b815
|
7
|
+
data.tar.gz: 4c1916d0f879fa8e16445e85beaa3545823bdb9e371373429469acdc0adb8ca7ee73d66ad2cdf1405792beb3d9085b091080f6b41f008d01be433d05b5163ddb
|
data/bin/sq
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
|
4
|
+
require 'trollop'
|
5
|
+
require 'sq'
|
6
|
+
|
7
|
+
opts = Trollop.options do
|
8
|
+
version "sq #{SQ.version}"
|
9
|
+
banner <<-EOS
|
10
|
+
sq is a bulk PDFs downloader
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
sq [options] <uri> [<regex>]
|
14
|
+
where [options] are:
|
15
|
+
EOS
|
16
|
+
|
17
|
+
opt :directory, 'Choose the output directory', :short => '-o', :type => :string, :default => '.'
|
18
|
+
end
|
19
|
+
|
20
|
+
if ARGV.empty?
|
21
|
+
puts 'Error: No URI provided. Use -h or --help to see the help.'
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
url, *regex_parts = ARGV
|
26
|
+
regex = regex_parts.join(' ')
|
27
|
+
|
28
|
+
SQ.process(url, Regexp.new(regex), opts)
|
data/lib/sq.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
|
4
|
+
require 'uri'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'nokogiri'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
module SQ
|
10
|
+
class << self
|
11
|
+
def version
|
12
|
+
'0.0.1'
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_agent
|
16
|
+
"SQ/#{version} +github.com/bfontaine/sq"
|
17
|
+
end
|
18
|
+
|
19
|
+
def query(uri, regex=/./)
|
20
|
+
uri = 'http://' + uri unless uri =~ /^https?:\/\//
|
21
|
+
|
22
|
+
doc = Nokogiri::HTML(open(uri, 'User-Agent' => user_agent))
|
23
|
+
links = doc.css('a[href]')
|
24
|
+
|
25
|
+
uris = links.map { |a| URI.join(uri, a.attr('href')) }
|
26
|
+
uris.select! { |u| u.path =~ /\.pdf$/i && u.to_s =~ regex }
|
27
|
+
|
28
|
+
uris.map do |u|
|
29
|
+
{
|
30
|
+
:uri => u.to_s,
|
31
|
+
:name => u.path.split('/').last
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def process(uri, regex=/./, opts={})
|
37
|
+
uris = self.query(uri, regex)
|
38
|
+
return 0 if uris.empty?
|
39
|
+
|
40
|
+
out = File.expand_path(opts[:directory] || '.')
|
41
|
+
|
42
|
+
Dir.mkdir(out) unless Dir.exists?(out)
|
43
|
+
|
44
|
+
uris.each do |u|
|
45
|
+
open("#{out}/#{u[:name]}", 'wb') do |f|
|
46
|
+
open(u[:uri], 'rb') do |resp|
|
47
|
+
f.write(resp.read)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/tests/tests.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'simplecov'
|
6
|
+
|
7
|
+
test_dir = File.expand_path( File.dirname(__FILE__) )
|
8
|
+
|
9
|
+
SimpleCov.start { add_filter '/tests/' } if ENV['COVERAGE']
|
10
|
+
|
11
|
+
require 'sq'
|
12
|
+
|
13
|
+
for t in Dir.glob( File.join( test_dir, '*_tests.rb' ) )
|
14
|
+
require t
|
15
|
+
end
|
16
|
+
|
17
|
+
class SQTests < Test::Unit::TestCase
|
18
|
+
|
19
|
+
# == UD#version == #
|
20
|
+
|
21
|
+
def test_sq_version
|
22
|
+
assert(SQ.version =~ /^\d+\.\d+\.\d+/)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
exit Test::Unit::AutoRunner.run
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Baptiste Fontaine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-10 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.1
|
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.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: trollop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colored
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: test-unit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fakeweb
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Download all PDFs linked in a Web page
|
112
|
+
email: batifon@yahoo.fr
|
113
|
+
executables:
|
114
|
+
- sq
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- lib/sq.rb
|
119
|
+
- tests/tests.rb
|
120
|
+
- bin/sq
|
121
|
+
homepage: https://github.com/bfontaine/sq
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.0.3
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Bulk PDFs downloader
|
145
|
+
test_files:
|
146
|
+
- tests/tests.rb
|