navitest 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/navitest +161 -0
- data/lib/navitest/version.rb +3 -0
- data/lib/navitest.rb +5 -0
- data/spec/navitest_spec.rb +9 -0
- data/spec/spec_helper.rb +14 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bcbf5342537dd88c0787485207f562366e06d6a4aa912f834bb9789851cab275
|
4
|
+
data.tar.gz: 6b65757d05f470ae9c6f2408b95eac79e768018ed937dccba78ce58574396165
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91079f77253119bc033a5a62686b4b96a58c84c9b3c2d91104907e9d83121e643f9b76aa4171aef47ae1d9b94074ccdbf60936b59d9ee8ca5f3e09a9bf0f505d
|
7
|
+
data.tar.gz: 9a566031b7d81c70bc2a2dcbec43e3f5bb2f0d243f0616f886bbc37b843119fc1a131c9e5cdb07291420cb3deeecbf98976422ddff8fcec2e046070b241e7eb4
|
data/bin/navitest
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'date'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'httparty'
|
7
|
+
require 'mail'
|
8
|
+
require 'json'
|
9
|
+
require 'securerandom'
|
10
|
+
|
11
|
+
navi_path = ENV["NAVI_PATH"]
|
12
|
+
spider_graph_path = navi_path + "/spider_graph.json"
|
13
|
+
spider_json = JSON.parse(File.read(spider_graph_path))
|
14
|
+
|
15
|
+
credential_path = navi_path + "/credential.json"
|
16
|
+
credential_json = JSON.parse(File.read(credential_path))
|
17
|
+
owner_email = credential_json["email"]
|
18
|
+
password = credential_json["password"]
|
19
|
+
token = ""
|
20
|
+
|
21
|
+
response = HTTParty.post("https://signin.navihq.com/oauth/token",
|
22
|
+
body: {
|
23
|
+
email: owner_email,
|
24
|
+
password: password,
|
25
|
+
grant_type: "password"
|
26
|
+
}
|
27
|
+
)
|
28
|
+
|
29
|
+
if(response.code != 200)
|
30
|
+
raise "Can't login to NAVI, Please update credentail.json file in NAVI_PATH"
|
31
|
+
else
|
32
|
+
puts "Authorized with SSO Web server"
|
33
|
+
token = "Token: #{response["access_token"]}##{owner_email}"
|
34
|
+
end
|
35
|
+
|
36
|
+
# system("#{navi_path}/bin/naviai &")
|
37
|
+
|
38
|
+
def settel_directory(path)
|
39
|
+
Dir.mkdir(path) unless Dir.exist?(path)
|
40
|
+
path
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_file(file_path, content)
|
44
|
+
file = File.new(file_path, "w")
|
45
|
+
file.puts(content)
|
46
|
+
file.close
|
47
|
+
end
|
48
|
+
|
49
|
+
emls_path = "#{navi_path}/emls"
|
50
|
+
FileUtils.remove_dir(emls_path,true)
|
51
|
+
settel_directory(emls_path)
|
52
|
+
|
53
|
+
puts "Start Creation of eml file"
|
54
|
+
|
55
|
+
spider_json.each do |key, quardent|
|
56
|
+
title = quardent["title"]
|
57
|
+
q1 = quardent["q1"]["title"]
|
58
|
+
q2 = quardent["q2"]["title"]
|
59
|
+
q3 = quardent["q3"]["title"]
|
60
|
+
q4 = quardent["q4"]["title"]
|
61
|
+
[q1, q2, q3, q4].each do |child_quardent|
|
62
|
+
puts "Create eml file for #{title} - #{child_quardent}"
|
63
|
+
for i in 0..20
|
64
|
+
eml_file_path = "#{emls_path}/#{child_quardent}#{i}.eml"
|
65
|
+
|
66
|
+
content = "
|
67
|
+
Delivered-To: #{owner_email}
|
68
|
+
From: Mikel Lindsaar <test@lindsaar.net>
|
69
|
+
To: Shree Ram Neupane <#{owner_email}>
|
70
|
+
Date: #{DateTime.now}
|
71
|
+
Content-Type: text/plain; charset=US-ASCII; format=flowed
|
72
|
+
Subject: #{child_quardent}
|
73
|
+
|
74
|
+
#{title}
|
75
|
+
#{child_quardent}
|
76
|
+
"
|
77
|
+
|
78
|
+
create_file(eml_file_path, content)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
puts "Complete Creation of eml files"
|
83
|
+
|
84
|
+
eml_files = Dir["#{navi_path}/emls/*.eml"]
|
85
|
+
download_path = "#{navi_path}/downloads"
|
86
|
+
FileUtils.remove_dir(download_path,true)
|
87
|
+
settel_directory(download_path)
|
88
|
+
download_email_path = settel_directory("#{download_path}/#{owner_email}")
|
89
|
+
inputs_path = settel_directory("#{download_email_path}/inputs")
|
90
|
+
meta_path = settel_directory("#{download_email_path}/meta")
|
91
|
+
text_path = settel_directory("#{download_email_path}/text")
|
92
|
+
plain_text_path = settel_directory("#{text_path}/plain")
|
93
|
+
|
94
|
+
count = eml_files.count
|
95
|
+
|
96
|
+
puts "Start parsing of #{count} eml files"
|
97
|
+
inputs_file = "#{inputs_path}/#{SecureRandom.uuid}"
|
98
|
+
File.write(inputs_file, "")
|
99
|
+
|
100
|
+
for i in 0..count
|
101
|
+
eml_file = eml_files[i]
|
102
|
+
mail = Mail.read(eml_file) if eml_file
|
103
|
+
file_name = SecureRandom.uuid
|
104
|
+
plain_text_file_path = "#{plain_text_path}/#{file_name}"
|
105
|
+
content = Base64.encode64(mail.decoded)
|
106
|
+
create_file(plain_text_file_path, content)
|
107
|
+
|
108
|
+
meta_file_path = "#{meta_path}/#{i+1}_#{file_name}.yml"
|
109
|
+
meta_content =
|
110
|
+
"
|
111
|
+
---
|
112
|
+
from: #{mail.from[0]}
|
113
|
+
to: #{mail.to[0]}
|
114
|
+
subject: #{mail.subject}
|
115
|
+
date: #{mail.date}
|
116
|
+
text_plain: \"#{plain_text_file_path}\"
|
117
|
+
"
|
118
|
+
create_file(meta_file_path, meta_content)
|
119
|
+
|
120
|
+
if(i%50 == 0 && i != 0)
|
121
|
+
naviai_response = HTTParty.post("http://localhost:9090/v2/metas",
|
122
|
+
headers: {
|
123
|
+
"Content-Type": "application/json"
|
124
|
+
},
|
125
|
+
body: {
|
126
|
+
"client_type": "local",
|
127
|
+
"list_meta_path": inputs_file,
|
128
|
+
"token": token
|
129
|
+
}.to_json
|
130
|
+
)
|
131
|
+
|
132
|
+
if(naviai_response.code != 200)
|
133
|
+
raise "Can't parse email."
|
134
|
+
else
|
135
|
+
puts "#{i} files parsed"
|
136
|
+
end
|
137
|
+
|
138
|
+
inputs_file = "#{inputs_path}/#{SecureRandom.uuid}"
|
139
|
+
File.write(inputs_file, "")
|
140
|
+
end
|
141
|
+
|
142
|
+
open(inputs_file, 'a') { |f|
|
143
|
+
f.puts meta_file_path
|
144
|
+
}
|
145
|
+
end
|
146
|
+
puts "Parsing Completed"
|
147
|
+
|
148
|
+
system("lsof -i tcp:9090 | grep naviai | awk {'print $2'} | xargs kill -9")
|
149
|
+
|
150
|
+
generate_csv_response = HTTParty.post(
|
151
|
+
"https://api2.navihq.com/v2/generate_csv_input?email=#{owner_email}",
|
152
|
+
headers: {"Authorization": token}
|
153
|
+
)
|
154
|
+
|
155
|
+
if(generate_csv_response.code != 204)
|
156
|
+
raise "Can't generate CSV."
|
157
|
+
else
|
158
|
+
puts "CSV file saved in S3"
|
159
|
+
end
|
160
|
+
|
161
|
+
puts "Completed!!, Wait for EMR Jobs"
|
data/lib/navitest.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "navitest"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: navitest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shreeramneupane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.11.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.11.3
|
27
|
+
description: Creates .eml files & sync those files and send to parser
|
28
|
+
email:
|
29
|
+
- shreeramneupane0@gmail.com
|
30
|
+
executables:
|
31
|
+
- navitest
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- bin/navitest
|
36
|
+
- lib/navitest.rb
|
37
|
+
- lib/navitest/version.rb
|
38
|
+
- spec/navitest_spec.rb
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
homepage: http://rubygems.org/gems/navitest
|
41
|
+
licenses: []
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.7.3
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Navi Test
|
63
|
+
test_files: []
|