km-export-processor 0.3.2 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bb2587b35e72048e37522352260cac0fe2c698c
4
- data.tar.gz: af9de5721a2e4edd457416db6f6dfc0be80936e6
3
+ metadata.gz: a7ad4d1f4f74a54916571718aa250758430598b3
4
+ data.tar.gz: 8a3f75352b6fee4fd11f5e7388abe6963c6d876f
5
5
  SHA512:
6
- metadata.gz: 3a4ceb8fb390f48f2e43bafc245eb23f04ebc35dca4405d580186daec4f9835c3639cf7091d9c8617ebba744c9cbcb395b945d605e8db9923f3696bffffd0d0e
7
- data.tar.gz: 56e3b9ec872a94b3b0b3681b63955e3b53a7d68dcd3b2f0d2d2ceac3f4efc503ab67c6e8311f57aeeb8229d7b202b8ae45732e280a5fd47f56ce0c28b6d5ec6b
6
+ metadata.gz: ca1736615b2a414012a744370813af77e2613c5679c1cb59bceb58d5d2c328e12ba02fc7bfffcb376f765cf5c64257cc1fcf701b78161a70f24d1de65a871e0f
7
+ data.tar.gz: eda70edec75818811bbc16b6880308a916bdcc30d435c37f7bfd68bd0e8eb4e24051bcf6f00216e46730c3367145f645833833660deaabf0bfd9f2b8de840835
@@ -28,11 +28,17 @@ class CLI < Thor
28
28
  KMExport.alias_parser(jsonfile)
29
29
  end
30
30
 
31
- desc "reimport [JSONFILE] [APIKEY]", "Takes KISSmetrics JSON, and a KM API key as input, and sends the data to KISSmetrics"
32
- def reimport(jsonfile, apikey)
31
+ desc "parse_identity [JSONFILE] [IDENTITY]", "Takes KISSmetrics JSON as an input, and separates any actions taken by the provided identity into their own file"
32
+ def parse_identity(jsonfile, identity)
33
+ puts "Parsing any actions done by #{identity} in #{jsonfile} into their own file"
34
+ KMExport.identity_parser(jsonfile, identity)
35
+ end
36
+
37
+ desc "reimport [JSONFILE] [APIKEY] [OFFSET]", "Takes KISSmetrics JSON, and a KM API key as input, and sends the data to KISSmetrics"
38
+ def reimport(jsonfile, apikey, offset=0)
33
39
  puts "Sending data from #{jsonfile} to KISSmetrics product with key: #{apikey}"
34
40
  reimporter = KMExport::Reimporter.new
35
- reimporter.send_to_KM(jsonfile, apikey)
41
+ reimporter.send_to_KM(jsonfile, apikey, offset.to_i)
36
42
  end
37
43
  end
38
44
 
@@ -10,4 +10,5 @@ require_relative 'converters/json_to_json'
10
10
  require_relative 'converters/json_to_csv'
11
11
  require_relative 'converters/json_compiler'
12
12
  require_relative 'reimporter'
13
- require_relative 'alias_parser'
13
+ require_relative 'parsers/identity_parser'
14
+ require_relative 'parsers/alias_parser'
@@ -0,0 +1,26 @@
1
+ module KMExport
2
+ def self.identity_parser(jsonfile, identity)
3
+ input = IO.open(IO.sysopen(jsonfile))
4
+ output_filename = Time.now.to_i.to_s + "_" + identity + "_results.json"
5
+ new_filename = Time.now.to_i.to_s + "_result.json"
6
+ File.open(output_filename, "w+").close
7
+ File.open(new_filename, "w+").close
8
+ identity_output = IO.open(IO.sysopen(output_filename, "w"), "w")
9
+ data_output = IO.open(IO.sysopen(new_filename, "w"), "w")
10
+
11
+ until input.eof?
12
+ row = input.readline
13
+ data = JSON.parse(row)
14
+ if data["_p"] == identity
15
+ identity_output.write(row)
16
+ identity_output.write("\n")
17
+ else
18
+ data_output.write(row)
19
+ data_output.write("\n")
20
+ end
21
+ end
22
+
23
+ input.close
24
+ File.delete(jsonfile)
25
+ end
26
+ end
@@ -5,6 +5,13 @@ class JSONQueue < Queue
5
5
  @counter = opts[:counter]
6
6
  end
7
7
 
8
+ def offset(amount)
9
+ puts "Offsetting by #{amount}"
10
+ amount.times do
11
+ @io.readline
12
+ end
13
+ end
14
+
8
15
  def add_to_queue
9
16
  100.times do
10
17
  self << JSON.parse(@io.readline)
@@ -16,11 +23,12 @@ end
16
23
 
17
24
  module KMExport
18
25
  class Reimporter
19
- def send_to_KM(json, key)
26
+ def send_to_KM(json, key, offset)
20
27
  pool = 10
21
28
  threads = []
22
- queue = JSONQueue.new({file: json, counter: 0})
29
+ queue = JSONQueue.new({file: json, counter: offset})
23
30
 
31
+ queue.offset(offset)
24
32
  queue.add_to_queue
25
33
 
26
34
  pool.times do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: km-export-processor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clay Whitley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kmts
@@ -130,11 +130,12 @@ executables:
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
- - lib/alias_parser.rb
134
133
  - lib/converters/json_compiler.rb
135
134
  - lib/converters/json_to_csv.rb
136
135
  - lib/converters/json_to_json.rb
137
136
  - lib/km-export-processor.rb
137
+ - lib/parsers/alias_parser.rb
138
+ - lib/parsers/identity_parser.rb
138
139
  - lib/reimporter.rb
139
140
  - spec/features/alias_parser_spec.rb
140
141
  - spec/features/json_to_csv_spec.rb