-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_nextcloud_notes.rb
42 lines (35 loc) · 1.16 KB
/
create_nextcloud_notes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true
require_relative "lib/google_keep/archive_parser"
require_relative "lib/nextcloud/from_google_keep_note"
require "getoptlong"
opts = GetoptLong.new(
["--input-dir", "-i", GetoptLong::REQUIRED_ARGUMENT],
["--output-dir", "-o", GetoptLong::REQUIRED_ARGUMENT],
)
input_dir = nil
output_dir = nil
opts.each do |opt, arg|
case opt
when "--input-dir"
input_dir = File.join(__dir__, arg)
when "--output-dir"
output_dir = File.join(__dir__, arg)
end
end
raise "No --input-dir provided" unless input_dir
raise "No --output-dir provided" unless output_dir
keep_notes = GoogleKeep::ArchiveParser.new(input_dir).notes
keep_notes.each do |keep_note|
subdir = if keep_note.archived?
"archived"
elsif keep_note.pinned?
"pinned"
elsif keep_note.trashed?
"trashed"
end
current_output_dir = output_dir
current_output_dir = File.join(current_output_dir, subdir) if subdir
Dir.mkdir(current_output_dir) unless File.exist?(current_output_dir)
nexcloud_note = Nextcloud::FromGoogleKeepNote.new(keep_note).call
nexcloud_note.write_file(path: current_output_dir)
end