forked from lifepillar/CSVKeychain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_category.rb
More file actions
executable file
·63 lines (54 loc) · 1.42 KB
/
add_category.rb
File metadata and controls
executable file
·63 lines (54 loc) · 1.42 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'csv'
require 'optparse'
# Position of fields in the CSV output by CSVKeychain
URL = 0
USERNAME = 1
PASSWORD = 2
TITLE = 3
NOTES = 4
CREATED = 5
MODIFIED = 6
KIND = 7
TYPE = 8
DOMAIN = 9
AUTHTYPE = 10
CLASS = 11
CREATOR = 12
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: add_category <path>"
opts.on("-o", "--output PATH", "Output file") do |o|
options[:out] = o
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end.parse!
input_file = ARGV.first
if input_file.nil?
puts "Please specify the path of a CSV file."
exit(1)
end
outfile = options.fetch(:out, File.join(File.dirname(input_file), File.basename(input_file, '.csv') + '-out.csv'))
out = CSV.open(outfile, "wb")
out << ["Where","Account","Password","Label","Comment","Created","Modified","Kind","Type","Domain","AuthType","Class","Creator","Category"]
CSV.foreach(input_file, :headers => true) do |row|
if row[KIND] =~ /secure\s+note/i or row[TYPE] == 'note'
group = 'Notes'
elsif row[KIND] =~ /network|802\.1|airport|handoff|sharing/i or row[URL] =~ /^.?(afp|ftp|smb|ssh|teln|vnc)/i
group = 'Network'
elsif row[CLASS] == 'inet' and row[URL] =~ /^.?(pop|smtp|imap|mail)/i
group = 'EMail'
elsif row[URL] =~ /:\/\//
group = 'Internet'
else
group = 'General'
end
row << group
out << row
end
out.close
puts "Done!"