kindleclippings 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +31 -0
- data/lib/clipping.rb +26 -0
- data/lib/kindleclippings.rb +59 -0
- metadata +68 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Georg Alexander Boe
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Kindleclippings
|
2
|
+
|
3
|
+
Kindleclippings is a ruby library for parsing annotations created on your kindle.
|
4
|
+
|
5
|
+
When you make annotations on a kindle, they are saved as a file called "My Clippings.txt" under the documents folder.
|
6
|
+
This library will parse these annotations/clippings and give you an array of ruby objects.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
require 'kindleclippings'
|
11
|
+
|
12
|
+
parser = KindleClippings::ClippingParser.new
|
13
|
+
|
14
|
+
clippings = parser.parse_file('My Clippings.txt')
|
15
|
+
clipping = clippings.last
|
16
|
+
|
17
|
+
clipping.book_title # => "Confessions of a Public Speaker"
|
18
|
+
clipping.author # => "Berkun Scott"
|
19
|
+
clipping.type # => :Highlight
|
20
|
+
clipping.added_on # => #<DateTime: 2009-12-14T19:10:00+00:00 (353545963/144,0/1,2299161)>
|
21
|
+
clipping.content # => "Most people say \"umm\" and \"uhh\" when they speak. These are called filler sounds, and we make them mostly to hold our place in conversation. You're letting the people you're talking to know you are not done speaking."
|
22
|
+
|
23
|
+
## Note on Patches/Pull Requests
|
24
|
+
|
25
|
+
* Fork the project.
|
26
|
+
* Make your feature addition or bug fix.
|
27
|
+
* Add tests for it. This is important so I don't break it in a
|
28
|
+
future version unintentionally.
|
29
|
+
* Commit, do not mess with rakefile, version, or history.
|
30
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
31
|
+
* Send me a pull request. Bonus points for topic branches.
|
data/lib/clipping.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module KindleClippings
|
3
|
+
class Clipping
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
attr_accessor :book_title, :author, :type, :location, :added_on, :content
|
7
|
+
|
8
|
+
def initialize()
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(title, author, type, location, added_on, content)
|
12
|
+
@book_title = title
|
13
|
+
@author = author
|
14
|
+
@type = type
|
15
|
+
@location = location
|
16
|
+
@added_on = DateTime.strptime(added_on, "%A, %B %d, %Y, %I:%M %p")
|
17
|
+
@content = content
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"#{@book_title} (#{author})\n" +
|
22
|
+
"- #{@type} Loc. #{@location} | Added on #{@added_on.strftime('%A, %B %d, %Y, %I:%M %p')}\n\n" +
|
23
|
+
"#{@content}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module KindleClippings
|
3
|
+
|
4
|
+
class ClippingParser
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/clipping.rb')
|
6
|
+
|
7
|
+
def parse_file(path)
|
8
|
+
parse(open(path).read)
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(filecontent)
|
12
|
+
@clippings = Array.new
|
13
|
+
|
14
|
+
filecontent.split("=" * 10).each do |clipping|
|
15
|
+
|
16
|
+
a_clipping = parse_clipping(clipping)
|
17
|
+
|
18
|
+
if a_clipping
|
19
|
+
@clippings << a_clipping
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
@clippings
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parse_clipping(clipping)
|
30
|
+
clipping.lstrip!
|
31
|
+
|
32
|
+
lines = Array.new
|
33
|
+
|
34
|
+
if RUBY_VERSION == "1.9.1"
|
35
|
+
lines = clipping.lines.to_a
|
36
|
+
else
|
37
|
+
lines = clipping.to_a
|
38
|
+
end
|
39
|
+
|
40
|
+
if lines.length < 4
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
|
44
|
+
first_line = lines[0].strip.scan(/^(.+) \((.+)\)$/i).first
|
45
|
+
second_line = lines[1].strip.scan(/^- (.+?) Loc. ([0-9-]*?) \| Added on (.+)$/i).first
|
46
|
+
|
47
|
+
title, author = *first_line
|
48
|
+
type, location, date = *second_line
|
49
|
+
content = String.new
|
50
|
+
|
51
|
+
if type == "Note"
|
52
|
+
content = lines[3..-1].join("")
|
53
|
+
else
|
54
|
+
content = lines[3]
|
55
|
+
end
|
56
|
+
Clipping.new(title, author, type.to_sym, location, date, content.strip)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kindleclippings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Georg Alexander Boe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-29 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: A gem to parse Kindle's "My Clippings.txt" file into ruby objects.
|
26
|
+
email: georg.boe@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.markdown
|
34
|
+
files:
|
35
|
+
- lib/clipping.rb
|
36
|
+
- lib/kindleclippings.rb
|
37
|
+
- LICENSE
|
38
|
+
- README.markdown
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/georgboe/kindleclippings
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.5
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: A gem to parse Kindle's "My Clippings.txt" file into ruby objects.
|
67
|
+
test_files: []
|
68
|
+
|