fyodor 0.2.5 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61b605527557fc96f8fbf0d526ee26a157d6dabf4544fbb8d3519197ad0ec45f
4
- data.tar.gz: be89647509157f9cab923b498f90b129c3cdb00836e3d8a3c2af5e692252f155
3
+ metadata.gz: dae694865dbdb0187906ad21b610ac7f9486819141f86392816a41fbe835f71c
4
+ data.tar.gz: 97c07e5ba51877015426221aed2158a20436f36d8afbca165b8433c20050e02a
5
5
  SHA512:
6
- metadata.gz: 8dfc0e521bf352f1c98ac7d7f1203f8cccbd6491a9c216754dbc2ae3072a30361e688f8fe96014719043c3abac866022d7322ae3d5cb155657f434818ac624a1
7
- data.tar.gz: 23c025a3c1bbdc206fa1d4cd4bfc6bccdd2e3de2a3735da74482d14c6cd5f74ed14cc834ac0851c5609c8be3aed1637e4312de405fb696594776a0c774731784
6
+ metadata.gz: ec0b9492639f2b77ba2523106db931b3363c42731cab3b456f83e6c7e91ccc6ec196d4cbe9d8798f62a5c452eed391fec521d7e8da56c537be51a224e93963bc
7
+ data.tar.gz: 359197fe0aeb85d76f1d025c2e3517a7fb02c60712989f79dd14be2004f50f3892a312b4114a3d29245d26a8f2e72f59dd4a2925c7c800f3dc63b435d63e4952
data/README.md CHANGED
@@ -6,7 +6,7 @@ Convert your Amazon Kindle highlights, notes and bookmarks into markdown files.
6
6
 
7
7
  This application parses `My Clippings.txt` from your Kindle and generates a markdown file for each book/document, in the format `#{Author} - #{Title}.md`. This way, your annotations are conveniently stored and easily managed.
8
8
 
9
- [For samples of the output, click here.](samples/)
9
+ [For samples of the output, click here.](docs/output_demo)
10
10
 
11
11
  To read more about the motivation and what problem it tries to solve, [check this blog post](http://rafaelc.org/blog/export-all-your-kindle-highlights-and-notes/).
12
12
 
@@ -40,16 +40,16 @@ $ gem update fyodor
40
40
 
41
41
  ## Configuration
42
42
 
43
- Fyodor has an optional configuration file, which is used for the following features.
43
+ Fyodor has an optional configuration file, which is used for the following.
44
44
 
45
45
  ### Languages
46
46
 
47
- If your Kindle is not in English, you should tell Fyodor how some things are called by your `My Clippings.txt` (e.g. highlights, pages, etc). _Note that basic parsing should still work without configuration, but you won't take advantage of many features, resulting in a dirtier output._
47
+ If your Kindle is not in English, you should tell Fyodor how some things are called by your `My Clippings.txt` (e.g. highlights, pages, etc). _Fyodor should still work without configuration, but you won't take advantage of many features, resulting in a dirtier output._
48
48
 
49
49
  1. Download the sample config to `~/.config/fyodor.toml` or `$XDG_CONFIG_HOME/fyodor.toml`:
50
50
 
51
51
  ```
52
- $ wget https://raw.githubusercontent.com/rccavalcanti/fyodor/master/fyodor.toml.sample -O ~/.config/fyodor.toml
52
+ $ wget https://raw.githubusercontent.com/rccavalcanti/fyodor/master/docs/fyodor.toml.sample -O ~/.config/fyodor.toml
53
53
  ```
54
54
 
55
55
  2. Open both the configuration and your `My Clippings.txt` in your preferred editor. Change the values in the `[parser]` section to mirror what you get in `My Clippings.txt`.
data/bin/fyodor CHANGED
@@ -1,15 +1,59 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "fyodor/cli"
4
-
5
- # Pass --trace to get the stack trace
6
- if ARGV.include?("--trace")
7
- ARGV.delete("--trace")
8
- Fyodor::CLI.new.main
9
- else
10
- begin
11
- Fyodor::CLI.new.main
12
- rescue StandardError => e
13
- abort(e.message)
3
+ require "fyodor"
4
+ require "fyodor/config_getter"
5
+ require "fyodor/stats_printer"
6
+ require "fyodor/version"
7
+ require "optimist"
8
+ require "pathname"
9
+
10
+ module Fyodor
11
+ class CLI
12
+ def main
13
+ parse_args
14
+ @config = ConfigGetter.new.config
15
+
16
+ if @cli_opts.trace
17
+ run
18
+ else
19
+ begin
20
+ run
21
+ rescue StandardError => e
22
+ abort(e.message)
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def get_path(path)
30
+ Pathname.new(path).expand_path
31
+ end
32
+
33
+ def default_output_dir
34
+ Pathname.new(Dir.pwd) + "fyodor_output"
35
+ end
36
+
37
+ def run
38
+ library = Library.new
39
+ ClippingsParser.new(@clippings_path, @config["parser"]).parse(library)
40
+ StatsPrinter.new(library).print
41
+ OutputWriter.new(library, @output_dir, @config["output"]).write_all
42
+ end
43
+
44
+ def parse_args
45
+ @cli_opts = Optimist::options do
46
+ version "Fyodor v#{Fyodor::VERSION}"
47
+ synopsis "Usage: fyodor [options] my_clippings_path [output_dir]"
48
+
49
+ opt :trace, "Show backtrace", :default => false
50
+ end
51
+
52
+ Optimist::die "Wrong number of arguments." if ARGV.count != 1 && ARGV.count != 2
53
+ @clippings_path = get_path(ARGV[0])
54
+ @output_dir = ARGV[1].nil? ? default_output_dir : get_path(ARGV[1])
55
+ end
14
56
  end
15
57
  end
58
+
59
+ Fyodor::CLI.new.main
@@ -31,9 +31,15 @@ module Fyodor
31
31
 
32
32
  title, author = @lines[0].scan(regex).first
33
33
  # If book has no author, regex fails.
34
- title = @lines[0] if title.nil?
34
+ if title.nil?
35
+ title = @lines[0]
36
+ author = ""
37
+ end
38
+
39
+ title = rm_zero_width_chars(title).strip
40
+ author = rm_zero_width_chars(author).strip
35
41
 
36
- {title: title.strip, author: author.to_s.strip}
42
+ {title: title, author: author}
37
43
  end
38
44
 
39
45
  def desc
@@ -93,5 +99,9 @@ module Fyodor
93
99
  raise "Entry is badly formatted" if @lines[1].strip.empty?
94
100
  raise "Entry is badly formatted" unless @lines[2].strip.empty?
95
101
  end
102
+
103
+ def rm_zero_width_chars(str)
104
+ str.gsub(/[\u200B-\u200D\uFEFF]/, '')
105
+ end
96
106
  end
97
107
  end
@@ -1,3 +1,3 @@
1
1
  module Fyodor
2
- VERSION = "0.2.5".freeze
2
+ VERSION = "0.2.6".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fyodor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Cavalcanti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-18 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toml
@@ -36,7 +36,6 @@ files:
36
36
  - bin/fyodor
37
37
  - lib/fyodor.rb
38
38
  - lib/fyodor/book.rb
39
- - lib/fyodor/cli.rb
40
39
  - lib/fyodor/clippings_parser.rb
41
40
  - lib/fyodor/config_getter.rb
42
41
  - lib/fyodor/core_extensions/hash/merging.rb
@@ -1,42 +0,0 @@
1
- require "fyodor/config_getter"
2
- require "fyodor/stats_printer"
3
- require "fyodor/library"
4
- require "fyodor/clippings_parser"
5
- require "fyodor/output_writer"
6
- require "pathname"
7
-
8
- module Fyodor
9
- class CLI
10
- USAGE = "Usage: #{File.basename($0)} my_clippings_path [output_dir]"
11
-
12
- def initialize
13
- get_args
14
- @config = ConfigGetter.new.config
15
- end
16
-
17
- def main
18
- library = Library.new
19
- ClippingsParser.new(@clippings_path, @config["parser"]).parse(library)
20
- StatsPrinter.new(library).print
21
- OutputWriter.new(library, @output_dir, @config["output"]).write_all
22
- end
23
-
24
-
25
- private
26
-
27
- def get_args
28
- abort(USAGE) if ARGV.count != 1 && ARGV.count != 2
29
-
30
- @clippings_path = get_path(ARGV[0])
31
- @output_dir = ARGV[1].nil? ? default_output_dir : get_path(ARGV[1])
32
- end
33
-
34
- def get_path(path)
35
- Pathname.new(path).expand_path
36
- end
37
-
38
- def default_output_dir
39
- Pathname.new(Dir.pwd) + "fyodor_output"
40
- end
41
- end
42
- end