joplin 0.1.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +3 -1
- data/Makefile +9 -0
- data/README.md +20 -1
- data/bin/joplin +71 -4
- data/lib/joplin.rb +29 -1
- data/lib/joplin/token.rb +14 -0
- data/lib/joplin/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fada7c3ac2927ba5715b67437eac2fa1df0a33a24596e7a8619beadcabe27d2
|
4
|
+
data.tar.gz: 694472244aad50df5c84395b647b40840e8aff6eafe76903ccd667806aeed50e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d006b40cf72590d3c193cd71bf918044f06d4c379447d492c869b3c6533aaa0835196e7219d5ca9e483707206e7c739849d39a925d06542b2ced1dfdb742d77
|
7
|
+
data.tar.gz: ffd27223a512c4538bb5e9156ad1ef1825a5f0123afc45907c2eeba4be719cd7ae0a596b2c638147cec3e76fe1a7cba0390321bcaeb93e5da3b07bade3bdf2a3
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
joplin (0.
|
4
|
+
joplin (0.2.2)
|
5
5
|
faraday (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -25,6 +25,7 @@ GEM
|
|
25
25
|
diff-lcs (>= 1.2.0, < 2.0)
|
26
26
|
rspec-support (~> 3.9.0)
|
27
27
|
rspec-support (3.9.3)
|
28
|
+
sqlite3 (1.4.2)
|
28
29
|
thor (1.0.1)
|
29
30
|
|
30
31
|
PLATFORMS
|
@@ -36,6 +37,7 @@ DEPENDENCIES
|
|
36
37
|
joplin!
|
37
38
|
rake (~> 13.0)
|
38
39
|
rspec (~> 3.0)
|
40
|
+
sqlite3 (~> 1.4)
|
39
41
|
thor (~> 1.0)
|
40
42
|
|
41
43
|
BUNDLED WITH
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -22,5 +22,24 @@ updating a note
|
|
22
22
|
note = Joplin::Notes.new "6e3811c7a73148a" # note id can be found in the information of any note
|
23
23
|
note.title = "a new note title"
|
24
24
|
note.save!
|
25
|
-
end
|
26
25
|
```
|
26
|
+
|
27
|
+
### A note on the token
|
28
|
+
|
29
|
+
If you've got joplin installed, you can do:
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
require "joplin/token"
|
33
|
+
token = Joplin::Token.get
|
34
|
+
```
|
35
|
+
|
36
|
+
to get the token programatically. It reads from the sqlite database located in `~/.config/joplin-desktop`
|
37
|
+
|
38
|
+
|
39
|
+
## CLI
|
40
|
+
|
41
|
+
### joplin nb2n --token <yourtoken> 'notebook name'
|
42
|
+
|
43
|
+
Will take a notebook and concatenate all notes into one for easy export to PDF
|
44
|
+
|
45
|
+
The token argument is optional and if you have it installed locally it will find the token
|
data/bin/joplin
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
4
|
+
|
5
|
+
require "joplin"
|
4
6
|
require 'thor'
|
7
|
+
require "joplin/token"
|
8
|
+
|
9
|
+
DIVIDER = %Q(
|
10
|
+
|
11
|
+
<svg height="50" width="460">
|
12
|
+
<style> .line { stroke-width: 1px; fill: black; stroke: black; } </style>
|
13
|
+
<g id="triangle"><path d="M0 30 L200 30 Q 220 25 200 35 Z" class="line" /></g>
|
14
|
+
<use xlink:href="#triangle" transform="scale(-1 1) translate(-450 0)"/>
|
15
|
+
<circle cx="225" cy="32" r="7" class="line"/>
|
16
|
+
</svg>
|
17
|
+
|
18
|
+
)
|
5
19
|
|
6
20
|
|
7
21
|
class MyCLI < Thor
|
@@ -10,14 +24,16 @@ class MyCLI < Thor
|
|
10
24
|
class_option :version, :type => :boolean
|
11
25
|
map ["-v", "--version"] => :version
|
12
26
|
map ["-h", "--help"] => :help
|
13
|
-
option :token
|
27
|
+
option :token
|
14
28
|
option :'dry-run', desc: "dry-run", aliases: '-n'
|
15
29
|
desc :clean, "clean unused resources"
|
16
30
|
def clean
|
17
|
-
Joplin::token = options[:token]
|
31
|
+
Joplin::token = options[:token] || Joplin::Token.get
|
32
|
+
puts "Please wait, this can take while."
|
18
33
|
Joplin::Resource.orphaned.map { |r|
|
19
34
|
r.delete if not options['dry-run']
|
20
|
-
|
35
|
+
would = "would have " if options['dry-run']
|
36
|
+
puts "#{would}deleted #{r.id}"
|
21
37
|
}
|
22
38
|
end
|
23
39
|
|
@@ -26,6 +42,57 @@ class MyCLI < Thor
|
|
26
42
|
def version
|
27
43
|
puts Joplin::VERSION
|
28
44
|
end
|
45
|
+
|
46
|
+
desc :nb2n, "concate all notes in a notebook to one note. Possible PDF export"
|
47
|
+
long_desc "The idea is to make a big note from all the notes in a notebook. PDF export or whatever export can happen from that. The notes are concatenated with a separator."
|
48
|
+
option :token
|
49
|
+
option :type, :type => :string
|
50
|
+
def nb2n(query)
|
51
|
+
Joplin::token = options[:token] || Joplin::Token.get
|
52
|
+
results = Joplin.search(query, { type: 'folder' })
|
53
|
+
nb = results[0];
|
54
|
+
if not (nb and nb['title'] == query)
|
55
|
+
abort "notebook #{query} not found"
|
56
|
+
end
|
57
|
+
|
58
|
+
notebook = Joplin::Notebook.new nb['id']
|
59
|
+
notes = notebook.notes
|
60
|
+
new_note = Joplin::Note.new
|
61
|
+
new_note.title = query
|
62
|
+
new_note.body = notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join(DIVIDER)
|
63
|
+
new_note.save!
|
64
|
+
puts "Saved: #{new_note.title} with id: #{new_note.id}"
|
65
|
+
end
|
66
|
+
|
67
|
+
desc :build, "build a note from a note containing references"
|
68
|
+
|
69
|
+
long_desc %Q(Takes a note and looks up all the referenced notes and makes a new
|
70
|
+
note from those. The notes are concatenated with a separator.\n\nIf you have a
|
71
|
+
line with 'title: a title' then it will be used for the title of the built
|
72
|
+
email.)
|
73
|
+
|
74
|
+
def build(id)
|
75
|
+
token
|
76
|
+
note = Joplin::Note.new id
|
77
|
+
notes = []
|
78
|
+
title = nil
|
79
|
+
note.body.each_line { |line|
|
80
|
+
title = $1 if line =~ /title: (.*)$/
|
81
|
+
line =~ /\(:\/([^)]+)\)/
|
82
|
+
notes.push Joplin::Note.new $1 if $1
|
83
|
+
}
|
84
|
+
new_note = Joplin::Note.new
|
85
|
+
new_note.title = title || "built: #{note.title}"
|
86
|
+
new_note.body = notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join(DIVIDER)
|
87
|
+
new_note.save!
|
88
|
+
puts "Saved: #{new_note.title} with id: #{new_note.id}"
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def token()
|
93
|
+
Joplin::token = options[:token] || Joplin::Token.get
|
94
|
+
raise "Couldn't find token in local database and it wasn't passed as an option. You better check yourself!" if not Joplin::token
|
95
|
+
end
|
29
96
|
end
|
30
97
|
|
31
98
|
MyCLI.start(ARGV)
|
data/lib/joplin.rb
CHANGED
@@ -10,6 +10,13 @@ module Joplin
|
|
10
10
|
@@token = token
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.search(query, opts = {})
|
14
|
+
url = "#{Joplin::uri}/search/?query=#{query}&token=#{Joplin::token}&type=#{opts[:type]}"
|
15
|
+
res = Faraday.get url
|
16
|
+
parsed = JSON.parse res.body
|
17
|
+
return parsed
|
18
|
+
end
|
19
|
+
|
13
20
|
def self.token
|
14
21
|
@@token
|
15
22
|
end
|
@@ -126,7 +133,9 @@ body: #{self.body}"""
|
|
126
133
|
|
127
134
|
private
|
128
135
|
def parse response
|
129
|
-
|
136
|
+
if response.body.empty?
|
137
|
+
raise "No note found with id #{@id}"
|
138
|
+
end
|
130
139
|
note = JSON.parse response.body
|
131
140
|
if response.status != 200
|
132
141
|
raise Error.new note["error"]
|
@@ -136,4 +145,23 @@ body: #{self.body}"""
|
|
136
145
|
@id = note["id"]
|
137
146
|
end
|
138
147
|
end
|
148
|
+
|
149
|
+
class Notebook
|
150
|
+
def initialize(id=nil)
|
151
|
+
|
152
|
+
@id = id
|
153
|
+
if id
|
154
|
+
url = "#{Joplin::uri}/folders/#{id}?token=#{Joplin::token}"
|
155
|
+
res = Faraday.get url
|
156
|
+
parsed = JSON.parse res.body
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def notes
|
161
|
+
url = "#{Joplin::uri}/folders/#{@id}/notes?token=#{Joplin::token}"
|
162
|
+
res = Faraday.get url
|
163
|
+
notes = JSON.parse res.body
|
164
|
+
notes.map! { |n| Joplin::Note.new n['id'] }
|
165
|
+
end
|
166
|
+
end
|
139
167
|
end
|
data/lib/joplin/token.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "sqlite3"
|
2
|
+
module Joplin
|
3
|
+
module Token
|
4
|
+
def self.get
|
5
|
+
begin
|
6
|
+
db = SQLite3::Database.new "#{ENV['HOME']}/.config/joplin-desktop/database.sqlite"
|
7
|
+
rows = db.execute("select value from settings where key='api.token';")
|
8
|
+
return rows.flatten.first
|
9
|
+
rescue
|
10
|
+
return nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/joplin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joplin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bretoi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- bin/setup
|
103
103
|
- joplin.gemspec
|
104
104
|
- lib/joplin.rb
|
105
|
+
- lib/joplin/token.rb
|
105
106
|
- lib/joplin/version.rb
|
106
107
|
homepage: http://github.com/danielb2/joplin
|
107
108
|
licenses:
|
@@ -110,7 +111,7 @@ metadata:
|
|
110
111
|
homepage_uri: http://github.com/danielb2/joplin
|
111
112
|
source_code_uri: http://github.com/danielb2/joplin
|
112
113
|
changelog_uri: http://github.com/danielb2/joplin
|
113
|
-
post_install_message:
|
114
|
+
post_install_message:
|
114
115
|
rdoc_options: []
|
115
116
|
require_paths:
|
116
117
|
- lib
|
@@ -126,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
127
|
version: '0'
|
127
128
|
requirements: []
|
128
129
|
rubygems_version: 3.0.3
|
129
|
-
signing_key:
|
130
|
+
signing_key:
|
130
131
|
specification_version: 4
|
131
132
|
summary: joplin API
|
132
133
|
test_files: []
|