export_list.rb - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
(HTM) git clone git://jay.scot/warvox
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
export_list.rb (1236B)
---
1 #!/usr/bin/env ruby
2 ###################
3
4 #
5 # Load the library path
6 #
7 base = __FILE__
8 while File.symlink?(base)
9 base = File.expand_path(File.readlink(base), File.dirname(base))
10 end
11 $:.unshift(File.join(File.expand_path(File.dirname(base)), '..', 'lib'))
12
13 require 'warvox'
14 require 'csv'
15
16 ENV['RAILS_ENV'] ||= 'production'
17 $:.unshift(File.join(File.expand_path(File.dirname(base)), '..'))
18
19 def usage
20 $stderr.puts "Usage: #{$0} [Job ID] <Type>"
21 exit
22 end
23
24 #
25 # Script
26 #
27
28 project_id = ARGV.shift
29 line_type = ARGV.shift
30
31 if(project_id and project_id == "-h")
32 usage()
33 end
34
35 if project_id.to_i == 0
36 usage()
37 end
38
39 require 'config/boot'
40 require 'config/environment'
41
42 if(not project_id)
43 $stderr.puts "Listing all projects"
44 $stderr.puts "===================="
45 Project.all.each do |j|
46 puts "#{j.id}\t#{j.name}\t#{j.created_at}"
47 end
48 exit
49 end
50
51 fields = %W{ number line_type caller_id answered busy audio_length ring_length peak_freq }
52 begin
53 $stdout.puts fields.to_csv
54 cond = { project_id: project_id.to_i }
55 if line_type
56 cond[:line_type] = line_type.downcase
57 end
58 Call.where(cond).order(number: :asc).each do |r|
59 out = []
60 fields.each do |f|
61 out << r[f].to_s
62 end
63 $stdout.puts out.to_csv
64 end
65 end