readability_importer 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,11 @@ module ReadabilityImporter
18
18
  :aliases => "-c",
19
19
  :desc => "Number of concurrency in parallel."
20
20
  })
21
+ method_option(:retry, {
22
+ :type => :boolean,
23
+ :aliases => "-r",
24
+ :desc => "Retry when failed."
25
+ })
21
26
  method_option(:verbose, {
22
27
  :type => :boolean,
23
28
  :aliases => "-v",
@@ -35,6 +40,7 @@ module ReadabilityImporter
35
40
  :verbose => options[:verbose],
36
41
  :from => options[:from],
37
42
  :max_concurrency => options[:concurrency],
43
+ :retry => options[:retry],
38
44
 
39
45
  :on_importing => proc do |urls|
40
46
  puts "Importing #{urls.size} url(s)..."
@@ -11,6 +11,7 @@ module ReadabilityImporter
11
11
  @from = options[:from] || "foo@bar"
12
12
  @max_concurrency = options[:max_concurrency] || 4
13
13
  @verbose = !!options[:verbose]
14
+ @retry = !!options[:retry]
14
15
 
15
16
  @on_importing = options[:on_importing]
16
17
  @on_imported = options[:on_imported]
@@ -23,7 +24,7 @@ module ReadabilityImporter
23
24
 
24
25
  EventMachine.run do
25
26
  iterator = EventMachine::Iterator.new(urls_set, @max_concurrency)
26
- iterator.each(proc do |urls, iterator|
27
+ iterator.each(proc do |urls, it|
27
28
  @on_importing.call(urls) if @on_importing
28
29
  EventMachine::Protocols::SmtpClient.send({
29
30
  :verbose => @verbose,
@@ -36,11 +37,14 @@ module ReadabilityImporter
36
37
  }).tap do |job|
37
38
  job.callback do
38
39
  @on_imported.call(urls) if @on_imported
39
- iterator.next
40
+ it.next
40
41
  end
41
- job.errback do
42
+ job.errback do |*args|
42
43
  @on_failed.call(urls) if @on_failed
43
- iterator.next
44
+ if @retry
45
+ iterator.instance_variable_get(:@list).unshift(urls)
46
+ end
47
+ it.next
44
48
  end
45
49
  end
46
50
  end, proc do
@@ -1,4 +1,5 @@
1
1
  require 'csv'
2
+ require 'uri'
2
3
 
3
4
  module ReadabilityImporter
4
5
  module Loader
@@ -51,6 +52,8 @@ module ReadabilityImporter
51
52
  end
52
53
 
53
54
  class InstapaperCsvLoader < Base
55
+ NON_ASCII_REGEXP = /[^\x00-\x7f]/u
56
+
54
57
  def self.desc
55
58
  "Path to CSV file"
56
59
  end
@@ -61,7 +64,7 @@ module ReadabilityImporter
61
64
 
62
65
  def load
63
66
  CSV.read(@path).map do |line|
64
- line[0]
67
+ URI.escape(line[0], NON_ASCII_REGEXP)
65
68
  end.reverse
66
69
  end
67
70
  end
@@ -1,3 +1,3 @@
1
1
  module ReadabilityImporter
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readability_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70152667209520 !ruby/object:Gem::Requirement
16
+ requirement: &70103673529860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0.beta.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70152667209520
24
+ version_requirements: *70103673529860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &70152667208940 !ruby/object:Gem::Requirement
27
+ requirement: &70103673529400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70152667208940
35
+ version_requirements: *70103673529400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70152667208340 !ruby/object:Gem::Requirement
38
+ requirement: &70103673528920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70152667208340
46
+ version_requirements: *70103673528920
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70152667207840 !ruby/object:Gem::Requirement
49
+ requirement: &70103673528380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70152667207840
57
+ version_requirements: *70103673528380
58
58
  description: Import many URLs to Readability.
59
59
  email:
60
60
  - niw@niw.at