promptcloud_data_api 0.0.2.beta1 → 0.0.3.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +1 -0
- data/lib/promptcloud_data_api.rb +26 -1
- data/lib/promptcloud_data_api/version.rb +1 -1
- metadata +10 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adadea9b77cbe21d9e29efba969e67c272ba5d03
|
4
|
+
data.tar.gz: 4e7397e675e66844536f11f42f86e97db3adc271
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e46be3e718566f293acc77adeb1c088425521e7de57c3e97ac8835035a96c5db537719779b09d3267f6f0db38b0fd7b628a6a65bd55efd61a187a6b90cadbb50
|
7
|
+
data.tar.gz: 86709d20e10e58d07c31a55e524067cc2fd6fb75d53e61e72e819229ec80844de0e78e475984503f7d9ad9223605e407e19809b90de0e3ab3aeea5f405484f9d
|
data/README.md
CHANGED
@@ -41,6 +41,7 @@ Directly install using gem. Command to run -
|
|
41
41
|
--loop download new data files and keep looking for new one(i.e it doesn't exit, if no new feed is found it will sleep, minimun sleep time is 10 secs and max sleep time is 300 secs)
|
42
42
|
--noloop download new data files and and exit, this is the default behaviour
|
43
43
|
--bcp to download data from PromptCloud backup server(high availability server, should use if main data api server is unreachable)
|
44
|
+
--ungzip unzip all the downloaded files and saves the files in a new directory
|
44
45
|
-h, --help Show this message
|
45
46
|
|
46
47
|
Example :
|
data/lib/promptcloud_data_api.rb
CHANGED
@@ -94,6 +94,23 @@ class PromptCloudApi
|
|
94
94
|
file << @conf_hash.to_yaml
|
95
95
|
end
|
96
96
|
end
|
97
|
+
def unzip_files(args_hash)
|
98
|
+
$stderr.puts "creating unzipped_files directory at #{@download_dir}"
|
99
|
+
unzip_file_path = File.join(@download_dir,"unzipped_files")
|
100
|
+
FileUtils::mkdir_p(unzip_file_path) unless File.directory?(unzip_file_path)
|
101
|
+
Dir.foreach(@download_dir) do |files|
|
102
|
+
next if files == '.' or files == '..' or files == "unzipped_files"
|
103
|
+
zip_file_basename = File.basename(files).gsub(".gz","")
|
104
|
+
zip_file = File.join(unzip_file_path,zip_file_basename)
|
105
|
+
dir_files = File.join(@download_dir,files)
|
106
|
+
output_file = File.open(zip_file,"w")
|
107
|
+
gz_file = Zlib::GzipReader.open(dir_files)
|
108
|
+
gz_file.each_line do |extract|
|
109
|
+
output_file.write(extract)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
$stderr.puts "Unzipped files are available at : #{unzip_file_path}\n\n"
|
113
|
+
end
|
97
114
|
|
98
115
|
def download_files(args_hash)
|
99
116
|
new_feed_exists = false
|
@@ -120,6 +137,7 @@ class PromptCloudApi
|
|
120
137
|
md5_filepath = args_hash[:md5_dir]+ "/#{md5_filename}"
|
121
138
|
if File.file?(md5_filepath) and File.open(md5_filepath).read.chomp.strip == md5sum
|
122
139
|
$stderr.puts "Skipping file #{url}, it has been downloaded earlier."
|
140
|
+
unzip_files(args_hash) if args_hash[:ungzip]
|
123
141
|
next
|
124
142
|
end
|
125
143
|
new_feed_exists = true
|
@@ -135,6 +153,7 @@ class PromptCloudApi
|
|
135
153
|
Zlib::GzipReader.open(outfile) {|gz|
|
136
154
|
content = gz.read
|
137
155
|
}
|
156
|
+
|
138
157
|
downloaded_md5 = Digest::MD5.hexdigest(content)
|
139
158
|
if md5sum == downloaded_md5
|
140
159
|
File.open(md5_filepath, "w"){|file| file.puts md5sum}
|
@@ -144,6 +163,8 @@ class PromptCloudApi
|
|
144
163
|
fetch_log_file.puts "Failed: #{url}"
|
145
164
|
File.delete(outfile)
|
146
165
|
end
|
166
|
+
|
167
|
+
unzip_files(args_hash) if args_hash[:ungzip]
|
147
168
|
rescue Exception => e
|
148
169
|
$stderr.puts "Failed to fetch url: #{url}, Exception: #{e.class}, #{e.message}"
|
149
170
|
fetch_log_file.puts "Failed: #{url}"
|
@@ -301,7 +322,7 @@ class PromptCloudApiArgParser
|
|
301
322
|
Example :
|
302
323
|
# Initial setup(default config)
|
303
324
|
ruby #{script_name} --perform_initial_setup --user <username> --pass <password> # API v1 requires valid userid and password
|
304
|
-
ruby #{script_name} --api_version v2 --perform_initial_setup --user <username> --
|
325
|
+
ruby #{script_name} --api_version v2 --perform_initial_setup --user <username> --client_auth_key <auth key> # API v2 requires valid user id and authentication key
|
305
326
|
|
306
327
|
# Download data
|
307
328
|
ruby #{script_name} # to download data of last 2 days (default)
|
@@ -401,6 +422,10 @@ END
|
|
401
422
|
opts.on("--bcp", "to download data from PromptCloud backup server(high availability server, should use if main data api server is unreachable)") do |v|
|
402
423
|
options[:bcp] = v
|
403
424
|
end
|
425
|
+
|
426
|
+
opts.on("--ungzip", "unzip all the downloaded files and saves the files in a new directory") do |v|
|
427
|
+
options[:ungzip] = v
|
428
|
+
end
|
404
429
|
|
405
430
|
opts.on_tail("-h", "--help", "Show this message") do
|
406
431
|
puts opts
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: promptcloud_data_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease: 6
|
4
|
+
version: 0.0.3.beta1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- PromptCloud
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rest-client
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: This gem can be used to download data from Promptcloud data API. It works
|
@@ -37,7 +34,7 @@ executables:
|
|
37
34
|
extensions: []
|
38
35
|
extra_rdoc_files: []
|
39
36
|
files:
|
40
|
-
- .gitignore
|
37
|
+
- ".gitignore"
|
41
38
|
- Gemfile
|
42
39
|
- LICENSE.txt
|
43
40
|
- README.md
|
@@ -48,26 +45,25 @@ files:
|
|
48
45
|
- promptcloud_data_api.gemspec
|
49
46
|
homepage: http://promptcloud.com
|
50
47
|
licenses: []
|
48
|
+
metadata: {}
|
51
49
|
post_install_message:
|
52
50
|
rdoc_options: []
|
53
51
|
require_paths:
|
54
52
|
- lib
|
55
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
54
|
requirements:
|
58
|
-
- -
|
55
|
+
- - ">="
|
59
56
|
- !ruby/object:Gem::Version
|
60
57
|
version: '0'
|
61
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
59
|
requirements:
|
64
|
-
- -
|
60
|
+
- - ">"
|
65
61
|
- !ruby/object:Gem::Version
|
66
62
|
version: 1.3.1
|
67
63
|
requirements: []
|
68
64
|
rubyforge_project:
|
69
|
-
rubygems_version:
|
65
|
+
rubygems_version: 2.4.8
|
70
66
|
signing_key:
|
71
|
-
specification_version:
|
67
|
+
specification_version: 4
|
72
68
|
summary: use it to query promptcloud indexed data
|
73
69
|
test_files: []
|