csv2influxdb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/csv2influxdb +56 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4ac5706b5dfc830c45879f948c043d050915ad2
|
4
|
+
data.tar.gz: dd86c61b9d035d552b97565fc384aee65eb33880
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16ec845c86b982350a08e2bb6e81f9a2c26408c5ca1ac407ac220a27a74874249c93d6a4d678c3d887dd04daff0929a2365c2964fe81b552073647f47794f63c
|
7
|
+
data.tar.gz: 54d0d3c2aaf85c0580a79026e36949c52b73f5e3ca2efd206ae90793e297a9603997e0dd4e5eb90f5ce2d942279a2187150b47e51b83553917fd54273bb6d848
|
data/bin/csv2influxdb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'csv'
|
3
|
+
require 'json'
|
4
|
+
require "slop"
|
5
|
+
|
6
|
+
opts = Slop.parse(:banner => 'csv2influxdb', :help => true ) do
|
7
|
+
on 'd', 'database=', 'Influxdb database name (Required)', :argument => true
|
8
|
+
on 'i', 'in', 'CSV filename to read in', :argument => true
|
9
|
+
on 'o', 'out', 'JSON filename to output to ', :argument => true
|
10
|
+
on 'p', 'pretty', 'Output pretty formatted json', :argument => false
|
11
|
+
end
|
12
|
+
|
13
|
+
unless opts.database?
|
14
|
+
puts 'You must specify a database name (-d)'
|
15
|
+
puts opts
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
name = opts["database"]
|
21
|
+
|
22
|
+
if opts.in?
|
23
|
+
@points = CSV.open(opts[:in]).readlines #Save CSV file to array
|
24
|
+
columns = @points.delete @points.first.to_a #Save CSV headers, then delete from CSV object
|
25
|
+
else
|
26
|
+
#When user passes in from stdin, there are extra characters like '\n', remove them
|
27
|
+
@points = Array.new
|
28
|
+
ARGF.each_line do |line|
|
29
|
+
line_gsubed = line.gsub /"/, '' #Remove extra quotes from the string
|
30
|
+
line_chomped = line_gsubed.chomp #Remove \n from string
|
31
|
+
split_lines = line_chomped.split(",") #Split at commas and then put into an array
|
32
|
+
@points.push(split_lines) #Create a multidementional array of arrays
|
33
|
+
end
|
34
|
+
columns = @points.shift #Delete first element of array (we only want the data, not the csv headers)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
#Convert arrays into hashes
|
39
|
+
influx_json = Hash[{ "name" => name, "columns" => columns, "points" => @points }]
|
40
|
+
|
41
|
+
#Save to file or print to stdout
|
42
|
+
if opts.out?
|
43
|
+
File.open(opts[:out], 'w') do |f|
|
44
|
+
if opts.pretty?
|
45
|
+
f.puts JSON.pretty_generate(influx_json)
|
46
|
+
else
|
47
|
+
f.puts influx_json.to_json
|
48
|
+
end
|
49
|
+
end
|
50
|
+
else
|
51
|
+
if opts.pretty?
|
52
|
+
puts JSON.pretty_generate(influx_json)
|
53
|
+
else
|
54
|
+
puts influx_json.to_json
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: csv2influxdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Spencer Owen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Converts CSV to JSON for influxdb
|
14
|
+
email: owenspencer@gmail.com
|
15
|
+
executables:
|
16
|
+
- csv2influxdb
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/csv2influxdb
|
21
|
+
homepage: https://github.com/spuder/csv2influxdb
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.2.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Converter for influxdb
|
45
|
+
test_files: []
|
46
|
+
has_rdoc:
|