-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsauce.rb
executable file
·77 lines (70 loc) · 2.1 KB
/
sauce.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env ruby
require 'smarter_csv'
require 'mongoid'
Mongoid.load!("./mongoid.yml", :development)
class MyModel
include Mongoid::Document
include Mongoid::Timestamps # gives you two fields - created_at, updated_at
field :Date, type: Date
field :Scanner, type: String
field :CSP, type: String
field :IP, type: String
field :Port, type: Integer
field :Latt, type: Float
field :Long, type: Float
field :Country, type: String
field :Continent, type: String
field :Region, type: String
field :City, type: String
field :PageTitle, type: String
field :App, type: String
field :AppStack, type: String
end
commands = []
ARGV.each {|arg| commands << arg}
# using chunks:
filename = ARGV[0]
if ARGV[1] == "banner"
n = SmarterCSV.process(filename, {:chunk_size => 100, :key_mapping => {
:Date => :Date,
:Scanner => :Scanner,
:CSP => :CSP,
:IP => :IP,
:Port => :Port,
:App => :App,
:AppStack => :AppStack
}}) do |chunk|
# we're passing a block in, to process each resulting hash / row (block takes array of hashes)
# when chunking is enabled, there are up to :chunk_size hashes in each chunk
MyModel.collection.insert( chunk ) # insert up to 100 records at a time
end
elsif ARGV[1] == "title"
n = SmarterCSV.process(filename, {:chunk_size => 100, :key_mapping => {
:Date => :Date,
:Scanner => :Scanner,
:CSP => :CSP,
:IP => :IP,
:Port => :Port,
:PageTitle => :PageTitle
}}) do |chunk|
# we're passing a block in, to process each resulting hash / row (block takes array of hashes)
# when chunking is enabled, there are up to :chunk_size hashes in each chunk
MyModel.collection.insert( chunk ) # insert up to 100 records at a time
end
else
n = SmarterCSV.process(filename, {:chunk_size => 100, :key_mapping => {
:Date => :Date,
:Scanner => :Scanner,
:CSP => :CSP,
:IP => :IP,
:Port => :Port,
:Latt => :Latt,
:Long => :Long,
:Country => :Country,
:Continent => :Continent,
:Region => :Region,
:City => :City
}}) do |chunk|
MyModel.collection.insert( chunk )
end
end