kynda 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bbcd196d96d5162afabc30545f53d1ad3b8900bd5457428408dda2b7fcf62acf
4
+ data.tar.gz: 06b3a5f8679bc51dd6271eaf22aa1c606d96ffa94757cbb7d51c552b4a2eacb4
5
+ SHA512:
6
+ metadata.gz: ef4d3ab95c0a428d5a0b5c565a9a0fcccdfb1f3629bbf7ca06ccf919ebacde6f0bc47623384e7eeb44b95c7fb1f99c70cb684fe74e192dc78fef558e16c3dd9e
7
+ data.tar.gz: 2355d1fb0fcaecbaf0142c20556212d87559aa7c5a2f2c6c45a2ab0d7836327aa1d796a60803f8318e92a1b263de74d36bcfddd299d89b0870eeb0b566c6998b
@@ -0,0 +1,5 @@
1
+ My Clippings
2
+ My Clippings_Amsterdam
3
+ My Clippings_Cat.txt
4
+ generated_files/
5
+ kynda_old_07062020.rb
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in kynda.gemspec
4
+
5
+ gem 'sinatra', '2.0.5'
6
+ gem 'rerun', '0.13.0'
7
+
8
+ group :test do
9
+ gem "rake", "~> 12.0"
10
+ gem "minitest", "~> 5.0"
11
+ end
@@ -0,0 +1,38 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ffi (1.13.1)
5
+ listen (3.2.1)
6
+ rb-fsevent (~> 0.10, >= 0.10.3)
7
+ rb-inotify (~> 0.9, >= 0.9.10)
8
+ minitest (5.14.1)
9
+ mustermann (1.1.1)
10
+ ruby2_keywords (~> 0.0.1)
11
+ rack (2.2.3)
12
+ rack-protection (2.0.5)
13
+ rack
14
+ rake (12.3.3)
15
+ rb-fsevent (0.10.4)
16
+ rb-inotify (0.10.1)
17
+ ffi (~> 1.0)
18
+ rerun (0.13.0)
19
+ listen (~> 3.0)
20
+ ruby2_keywords (0.0.2)
21
+ sinatra (2.0.5)
22
+ mustermann (~> 1.0)
23
+ rack (~> 2.0)
24
+ rack-protection (= 2.0.5)
25
+ tilt (~> 2.0)
26
+ tilt (2.0.10)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ minitest (~> 5.0)
33
+ rake (~> 12.0)
34
+ rerun (= 0.13.0)
35
+ sinatra (= 2.0.5)
36
+
37
+ BUNDLED WITH
38
+ 2.1.4
@@ -0,0 +1,36 @@
1
+ # Kynda
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kynda`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kynda'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kynda
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kynda.
36
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kynda"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ require './kynda_app'
2
+ run Sinatra::Application
@@ -0,0 +1,4 @@
1
+ gedogen, which means “technically illegal but officially tolerated.”
2
+ Amsterdam is famous for one thing (besides canals, and cannabis cafés, and prostitutes): the tattered, ancient, much-misunderstood word liberalism. Amsterdam is, by most accounts, the most liberal place on earth.
3
+ Multiculturalism proved to be a failure. It was leading not to a mixed society but to a multiplicity of ghettoized communities living next to but cut off from one another: the very opposite of a “society.”
4
+ “We were against authority and ownership. Buying real estate was for patsers.” (The word doesn’t translate well, but “establishment assholes” gets close.)
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/kynda/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "kynda"
5
+ spec.version = Kynda::VERSION
6
+ spec.authors = ["SamGarner"]
7
+ spec.email = ["samuel.w.garner@gmail.com"]
8
+
9
+ spec.summary = %q{Kindle 'My Clippings' organization and clean up}
10
+ #spec.description = %q{TODO: Write a longer description or delete this line.}
11
+ spec.homepage = "https://github.com/SamGarner/Kynda/settings"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/SamGarner/Kynda/"
18
+ spec.metadata["changelog_uri"] = "https://github.com/SamGarner/Kynda/"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'sinatra'
2
+
3
+ get '/' do
4
+ erb :index
5
+ end
6
+
7
+ get '/about' do
8
+ erb :about
9
+ end
10
+
11
+ get '/clippings_upload' do
12
+ erb :clippings_upload
13
+ end
@@ -0,0 +1,26 @@
1
+ book_title_regexp = /={10}\r\n(.*)\r\n/
2
+ kindle_clippings = "My Clippings"
3
+ titles = File.read(kindle_clippings).scan(book_title_regexp).flatten.uniq!
4
+ today = Time.now.strftime("%Y%m%d")
5
+ all_highlights_filename = "All_Kindle_Highlights #{today}.txt"
6
+
7
+ File.write(all_highlights_filename,"")
8
+
9
+ titles.each { |title|
10
+
11
+ if title[0] =~ /[\w]/
12
+ corrected_title = title
13
+ else
14
+ corrected_title = title[1..-1]
15
+ end
16
+
17
+ clippings = File.read(kindle_clippings).scan(
18
+ /#{Regexp.quote(corrected_title)}(.*)\r\n(.*)\r\n\r\n(.*)\r\n=======/).flatten
19
+ highlights = clippings.reject { |clipping| clipping.match(
20
+ /#{Regexp.quote("- Your Highlight")}/) || clipping.length < 2 }
21
+ File.write("#{corrected_title.strip} #{today}.txt", highlights.join("\n\n"))
22
+ File.write(all_highlights_filename,
23
+ "="*80 +"\n#{corrected_title.strip}\n\n", mode:"a")
24
+ File.write(all_highlights_filename,
25
+ highlights.join("\n\n") + "\n", mode:"a")
26
+ }
@@ -0,0 +1,28 @@
1
+ # **** Insert overall script steps here ****
2
+
3
+ # Get list of unique book titles from Kindle clippings .txt file
4
+ book_title_regexp = /={10}\n(.*)\n/
5
+ titles = File.read("shortclippings.txt").scan(book_title_regexp).flatten.uniq!
6
+
7
+ # Reset aka wipe the all encompassing highlights file with today's date
8
+ today = Time.now.strftime("%Y%m%d")
9
+ File.write("All_Kindle_Highlights #{today}.txt","")
10
+
11
+ # Iterate over each title
12
+ # create a file with highlights for each book
13
+ # create an all-encompassing highlight file, grouped by book
14
+ titles.each { |title|
15
+ clippings = File.read("shortclippings.txt").scan(
16
+ /#{Regexp.quote(title)}(.*)\n(.*)\n\n(.*)\n=======/).flatten
17
+ highlights = clippings.reject { |clipping| clipping.match(
18
+ /#{Regexp.quote("- Your Highlight")}/) || clipping.length < 2 }
19
+ # write file for each book with associated quotes
20
+ File.write("#{title.strip} #{today}.txt", highlights.join("\n\n"))
21
+ # write file containing all kindle quotes, grouped by book
22
+ # writes in a break/line of ='s between books and then the book's title
23
+ File.write("All_Kindle_Highlights #{today}.txt",
24
+ "="*80 +"\n#{title.strip}\n\n", mode:"a")
25
+ # writes in all the highlights for the given book
26
+ File.write("All_Kindle_Highlights #{today}.txt",
27
+ highlights.join("\n\n") + "\n", mode:"a")
28
+ }
@@ -0,0 +1,34 @@
1
+ # **** Insert overall script steps here ****
2
+
3
+ # Get list of unique book titles from Kindle clippings .txt file
4
+ book_title_regexp = /={10}\r\n(.*)\r\n/
5
+ kindle_clippings = "My Clippings"
6
+ titles = File.read(kindle_clippings).scan(book_title_regexp).flatten.uniq!
7
+ today = Time.now.strftime("%Y%m%d")
8
+ all_highlights_filename = "All_Kindle_Highlights #{today}.txt"
9
+
10
+ #titles = File.read("My Clippings").scan(/={10}\r\n(.*)\r\n/).flatten.uniq!
11
+
12
+ # Reset aka wipe the all encompassing highlights file with today's date
13
+ File.write(all_highlights_filename,"")
14
+
15
+ # Iterate over each title
16
+ # create a file with highlights for each book
17
+ # create an all-encompassing highlight file, grouped by book
18
+ titles.each { |title|
19
+ clippings = File.read(kindle_clippings).scan(
20
+ /#{Regexp.quote(title)}(.*)\r\n(.*)\r\n\r\n(.*)\r\n=======/).flatten
21
+ highlights = clippings.reject { |clipping| clipping.match(
22
+ /#{Regexp.quote("- Your Highlight")}/) || clipping.length < 2 }
23
+ # write file for each book with associated quotes
24
+ File.write("#{title.strip} #{today}.txt", highlights.join("\n\n"))
25
+ # write file containing all kindle quotes, grouped by book
26
+ # writes in a break/line of ='s between books and then the book's title
27
+ File.write(all_highlights_filename,
28
+ "="*80 +"\n#{title.strip}\n\n", mode:"a")
29
+ # writes in all the highlights for the given book
30
+ File.write(all_highlights_filename,
31
+ highlights.join("\n\n") + "\n", mode:"a")
32
+ }
33
+
34
+ # have 'kindle_clippings' variable able to accept an input - would rather enforce default name
@@ -0,0 +1,43 @@
1
+ # Get list of unique book titles from Kindle clippings .txt file
2
+ # Create empty file that will contain highlights from every book
3
+ book_title_regexp = /={10}\r\n(.*)\r\n/
4
+ kindle_clippings = "My Clippings"
5
+ titles = File.read(kindle_clippings).scan(book_title_regexp).flatten.uniq!
6
+ today = Time.now.strftime("%Y%m%d")
7
+ all_highlights_filename = "All_Kindle_Highlights #{today}.txt"
8
+
9
+ # Reset/wipe the all encompassing highlights file for today's date
10
+ File.write(all_highlights_filename,"")
11
+
12
+ # Iterate over each title
13
+ # create a file with highlights for each book
14
+ # append (grouped) highlights for each book to the all-encompassing highlight file
15
+ titles.each { |title|
16
+ # If loop added because every so often, was getting a book title with
17
+ # leading spaces - which lead to some repetitive files and highlights
18
+ # problem child: Amsterdam: A History of the World's Most Liberal City (Shorto, Russell)
19
+ if title[0] =~ /[\w]/
20
+ corrected_title = title
21
+ else
22
+ corrected_title = title[1..-1]
23
+ end
24
+
25
+ # 'clippings' pulls the text between the line containing the title and author
26
+ # and the === break line before the next highlight. This returns one
27
+ # match listing the page location and date of the highlight, one match of an
28
+ # empty line and one match with the desired highlighted conent (pulled out
29
+ # into 'highlights' variable)
30
+ clippings = File.read(kindle_clippings).scan(
31
+ /#{Regexp.quote(corrected_title)}(.*)\r\n(.*)\r\n\r\n(.*)\r\n=======/).flatten
32
+ highlights = clippings.reject { |clipping| clipping.match(
33
+ /#{Regexp.quote("- Your Highlight")}/) || clipping.length < 2 }
34
+ # write file for each book with associated quotes, tagged with today's date
35
+ File.write("#{corrected_title.strip} #{today}.txt", highlights.join("\n\n"))
36
+ # write file containing all quotes, grouped by book, tagged w/today's date
37
+ # writes in a break/line of ='s between books and then the book's title
38
+ File.write(all_highlights_filename,
39
+ "="*80 +"\n#{corrected_title.strip}\n\n", mode:"a")
40
+ # writes in all the highlights for the given book
41
+ File.write(all_highlights_filename,
42
+ highlights.join("\n\n") + "\n", mode:"a")
43
+ }
@@ -0,0 +1,45 @@
1
+ require "kynda/version"
2
+
3
+ # Get list of unique book titles from Kindle clippings .txt file
4
+ # Create empty file that will contain highlights from every book
5
+ book_title_regexp = /={10}\r\n(.*)\r\n/
6
+ kindle_clippings = "My Clippings"
7
+ titles = File.read(kindle_clippings).scan(book_title_regexp).flatten.uniq!
8
+ today = Time.now.strftime("%Y%m%d")
9
+ all_highlights_filename = "All_Kindle_Highlights #{today}.txt"
10
+
11
+ # Reset/wipe the all encompassing highlights file for today's date
12
+ File.write(all_highlights_filename,"")
13
+
14
+ # Iterate over each title
15
+ # create a file with highlights for each book
16
+ # append (grouped) highlights for each book to the all-encompassing highlight file
17
+ titles.each { |title|
18
+ # If loop added because every so often, was getting a book title with
19
+ # leading spaces - which lead to some repetitive files and highlights
20
+ # problem child: Amsterdam: A History of the World's Most Liberal City (Shorto, Russell)
21
+ if title[0] =~ /[\w]/
22
+ corrected_title = title
23
+ else
24
+ corrected_title = title[1..-1]
25
+ end
26
+
27
+ # 'clippings' pulls the text between the line containing the title and author
28
+ # and the === break line before the next highlight. This returns one
29
+ # match listing the page location and date of the highlight, one match of an
30
+ # empty line and one match with the desired highlighted conent (pulled out
31
+ # into 'highlights' variable)
32
+ clippings = File.read(kindle_clippings).scan(
33
+ /#{Regexp.quote(corrected_title)}(.*)\r\n(.*)\r\n\r\n(.*)\r\n=======/).flatten
34
+ highlights = clippings.reject { |clipping| clipping.match(
35
+ /#{Regexp.quote("- Your Highlight")}/) || clipping.length < 2 }
36
+ # write file for each book with associated quotes, tagged with today's date
37
+ File.write("#{corrected_title.strip} #{today}.txt", highlights.join("\n\n"))
38
+ # write file containing all quotes, grouped by book, tagged w/today's date
39
+ # writes in a break/line of ='s between books and then the book's title
40
+ File.write(all_highlights_filename,
41
+ "="*80 +"\n#{corrected_title.strip}\n\n", mode:"a")
42
+ # writes in all the highlights for the given book
43
+ File.write(all_highlights_filename,
44
+ highlights.join("\n\n") + "\n", mode:"a")
45
+ }
@@ -0,0 +1,3 @@
1
+ module Kynda
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,50 @@
1
+ #split on title line
2
+ #group by titles
3
+ #format
4
+
5
+ # File.read eg: text = File.read("clippings.txt")
6
+
7
+ # Regex to get titles: /==========(.*)\n(.*)/
8
+
9
+ titles = File.read("shortclippings.txt").scan(/={10}\n(.*)\n/).flatten
10
+
11
+ # remove duplicates
12
+ #.inject combo with .include?
13
+
14
+ titlelist = titles.uniq
15
+ #with Regex, first line is missing add in with something like:
16
+ #>> titlelist.include?(File.readlines("shortclippings.txt")[0]) BUT need to get that other leading space off first then to avoid doubling down on the Amsterdam book
17
+
18
+ ## skip this for now but the Amsterdam title example has a leading space, can't get it off without making things worse
19
+ titlelist.map {|t| t.strip}
20
+ titlelist.map {|t| t.to_s.strip}
21
+
22
+ # each loop...for each title, find all the highlights and output (combined file and individual books files?)
23
+ ##look for match on title[n](.*)={10}/m
24
+
25
+ puts File.read("shortclippings.txt").scan(/#{Regexp.quote(titlelist[0])}/)
26
+ ##the code on the next line below will return everything for a given title, that is below
27
+ ##the title line and above the ========== line (includes the your highlight page/date/time line)
28
+ ##put all these into a hash/array organized by book and then work on cleaning them up?
29
+ puts File.read("shortclippings.txt").scan(/#{Regexp.quote(titlelist[0])}(.*)\n(.*)\n\n(.*)\n=======/)
30
+ #looks like can add .flatten to this and then want every third element as a quote [0],[2],[5],etc.
31
+ # NOTE - using titlelist[0] will only give us clippings for the first book, how to iterate this?
32
+
33
+ ##OLD THOUGHTS
34
+ # get i for 0 ...quote length, then pull out the modul0 3 ones (would need to add in [0]
35
+ # or unshift a few placeholder elements to the front of the array...iterate for each quotes[i] value?)
36
+ #clippings.unshift #one time means [3], [6], etc will pull out actual clippings now.
37
+
38
+ #could also use reject to just get true 'clippings' in
39
+ #a variable and then use File.write to add the to the file (apppend
40
+ #if dont' want to overwrite
41
+ ##### REVERSE CLIPPING AND QUOTE TERMINOLOGY #####
42
+ highlights = clippings.reject { |clipping| clipping.match(/#{Regexp.quote("- Your Highlight")}/) || clipping.length < 2 }
43
+
44
+ ##highlights variable will now hold all 'true' highlights and no empty strings
45
+ ##or location time values
46
+
47
+ #output to file works, may want to insert empty row between each
48
+ #need to include title/rename file based on title
49
+ #may also want to append into "all highlights" file
50
+ File.write('file_title_stub.txt', highlights.join("\n"))
@@ -0,0 +1,40 @@
1
+ Amsterdam: A History of the World's Most Liberal City (Shorto, Russell)
2
+ - Your Highlight on page 15 | Location 200-201 | Added on Thursday, January 26, 2017 6:01:54 AM
3
+
4
+ gedogen
5
+ ==========
6
+ Amsterdam: A History of the World's Most Liberal City (Shorto, Russell)
7
+ - Your Highlight on page 15 | Location 200-201 | Added on Thursday, January 26, 2017 6:02:03 AM
8
+
9
+ gedogen, which means “technically illegal but officially tolerated.”
10
+ ==========
11
+ Amsterdam: A History of the World's Most Liberal City (Shorto, Russell)
12
+ - Your Highlight on page 16 | Location 213-214 | Added on Thursday, January 26, 2017 6:04:20 AM
13
+
14
+ Amsterdam is famous for one thing (besides canals, and cannabis cafés, and prostitutes): the tattered, ancient, much-misunderstood word liberalism. Amsterdam is, by most accounts, the most liberal place on earth.
15
+ ==========
16
+ Amsterdam: A History of the World's Most Liberal City (Shorto, Russell)
17
+ - Your Highlight on page 21 | Location 299-300 | Added on Thursday, January 26, 2017 6:21:08 AM
18
+
19
+ Multiculturalism proved to be a failure. It was leading not to a mixed society but to a multiplicity of ghettoized communities living next to but cut off from one another: the very opposite of a “society.”
20
+ ==========
21
+ Amsterdam: A History of the World's Most Liberal City (Shorto, Russell)
22
+ - Your Highlight on page 24 | Location 336-338 | Added on Thursday, January 26, 2017 6:26:11 AM
23
+
24
+ “We were against authority and ownership. Buying real estate was for patsers.” (The word doesn’t translate well, but “establishment assholes” gets close.)
25
+ ==========
26
+ Deep Work (Cal Newport)
27
+ - Your Highlight on Location 1391-1393 | Added on Wednesday, July 1, 2020 7:09:58 AM
28
+
29
+ In all of these examples, it’s not just the change of environment or seeking of quiet that enables more depth. The dominant force is the psychology of committing so seriously to the task at hand.
30
+ ==========
31
+ Deep Work (Cal Newport)
32
+ - Your Highlight on Location 1394-1395 | Added on Wednesday, July 1, 2020 7:10:07 AM
33
+
34
+ These gestures push your deep goal to a level of mental priority that helps unlock the needed mental resources. Sometimes to go deep, you must first go big.
35
+ ==========
36
+ Egypt on the Brink: From the Rise of Nasser to the Fall of Mubarak (Osman, Tarek)
37
+ - Your Highlight on page 41 | Location 700-705 | Added on Thursday, August 2, 2018 6:27:09 PM
38
+
39
+ Free trade, open markets and vast opportunities for wealth creation turned Egypt into a regional commercial and trading destination. One consequence was a flow of immigrants; the number of foreigners in the country rose from 10,000 in the 1840s (the first relatively reliable census) to around 90,000 in the 1880s, and more than 1.5 million by the 1930s. The major immigrant populations included Greeks, Jews and Armenians.24 The ensuing cosmopolitanism infused Egyptian society with tolerance, open-mindedness and glamour adding to the country's ‘seductive soft power’, and gave the liberal experiment a certain international appeal.
40
+ ==========