datahunter 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e49d1f617fcbb9d2374ca33fa8c23e37628406dd
4
- data.tar.gz: 6d6c00bc69b7bb30d1eea9030cfbc433357b0639
3
+ metadata.gz: c8bba1b0aa033c04e07c0e27279df43485da2013
4
+ data.tar.gz: 01688fd2862ff969dae99fabfccce51f3a3c4064
5
5
  SHA512:
6
- metadata.gz: ce5b6e7e68543ef2e5a47730960dc32ef81d050b885627c2e60d48aeb2ce65a9da6d4317a593c9f156caf3da79ebca17b9cf671b889b09a603dac4e90a54cf1b
7
- data.tar.gz: 14052b66fddb63d34582015f9301e69c9a6e20c94933357ea764e7dadc0f7983917319108c1ddf2fd5ea57294bf58b15719279bd1a9975901f26eb332ad0c7fd
6
+ metadata.gz: fccec23786af7fb1fa4e5dd2de142f8b7c70e5fcaa7fc35a9585bee0197ce99369159730a80a54811f99011fd6ffd3e67711621642cfd7dad8b16ca50771bc59
7
+ data.tar.gz: ff5d6fb9d643d993252bed1d251d10f44b196dbe2379b48dfa31cbd9331beb5ebd60ba1a44d00b186c2b89b37050773b102344313fda3cddca38e621fa28927e
data/.gitignore CHANGED
@@ -11,4 +11,5 @@
11
11
  *.so
12
12
  *.o
13
13
  *.a
14
+ *.gem
14
15
  mkmf.log
data/README.md CHANGED
@@ -1,26 +1,16 @@
1
1
  # Datahunter
2
2
 
3
- TODO: Write a gem description
3
+ ![screenshot](./logo.png)
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'datahunter'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
7
  $ gem install datahunter
20
8
 
21
9
  ## Usage
22
10
 
23
- TODO: Write usage instructions here
11
+ $ hunter find population france
12
+
13
+ ![usage](./hunter.gif)
24
14
 
25
15
  ## Contributing
26
16
 
data/bin/hunter CHANGED
@@ -8,131 +8,67 @@ require 'rest_client'
8
8
  require 'launchy'
9
9
  require 'colorize'
10
10
 
11
- program :version, '0.0.3'
11
+ program :version, Datahunter::VERSION
12
12
  program :description, 'Find open data easily and quicker than ever'
13
13
 
14
- feedback_url = "https://docs.google.com/forms/d/1yNzZjCCXvWHQCbWz4sx-nui3LafeeLcT7FF9T-vbKvw/viewform"
15
-
16
14
  command :find do |c|
17
15
  c.syntax = 'hunter find keyword [spatial-coverage] [temporal-coverage]'
18
- c.summary = 'Returns the 3 most popular (most reused, viewed, etc) datasets corresponding to the triple keyword, spatial-coverage and temporal-coverage'
16
+ c.summary = 'Returns the 3 most popular (most reused, viewed, etc) datasets corresponding '\
17
+ 'to the triple keyword, spatial-coverage and temporal-coverage'
19
18
  c.description = c.summary
20
19
  c.example 'Find open data for the U.S. population', 'hunter find population us'
21
20
  c.action do |args, options|
22
- tag = args[0]
23
- geo = args[1]
24
- temp = args[2]
25
21
 
26
- tag = tag.downcase.split.first if tag
27
- geo = geo.downcase if geo
28
-
29
22
  start_time = Time.now
30
23
 
31
- if geo.nil? and temp.nil?
32
- url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}"
33
- elsif temp.nil?
34
- url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&spatial=#{geo}"
35
- elsif geo.nil?
36
- url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&temporal=#{temp}"
37
- else
38
- url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&spatial=#{geo}&temporal=#{temp}"
39
- end
40
-
41
- response = RestClient.get(url, :content_type => :json){ |response, request, result, &block|
42
- elapsed_time = Time.now - start_time
43
- case response.code
44
- when 200
45
- ds = JSON.parse(response.body).reverse
46
- puts "### Response in #{elapsed_time} seconds".colorize(:blue)
47
- puts "### Looks like we've got something for you!".colorize(:blue)
48
- puts
49
- puts ("title: ".colorize(:green) + "#{ds[0]["title"]}")
50
- puts ("description: ".colorize(:green) + "#{ds[0]["description"]}")
51
- puts ("publisher: ".colorize(:green) + "#{ds[0]["publisher"]}")
52
- puts ("temporal: ".colorize(:green) + "#{ds[0]["temporal"]}")
53
- puts ("spatial: ".colorize(:green) + "#{ds[0]["spatial"]}")
54
- puts ("created: ".colorize(:green) + "#{ds[0]["created"]}")
55
- puts ("updated: ".colorize(:green) + "#{ds[0]["updated"]}")
56
- puts ("score: ".colorize(:green) + "#{ds[0]["huntscore"]}")
57
- puts
58
- case ask "### get the data? (y/n)".colorize(:yellow)
59
- when 'y'
60
- Launchy.open(ds[0]["uri"], options = {})
61
- when 'n'
62
- if ds[1].nil?
63
- puts ("Remember, this is a first prototype, there will surely be a lot more datasets indexed soon. If you want us to find a dataset for you, or if you just want to give us a feedback, don't hesitate!".colorize(:red))
64
- case ask "### give feedback? (y/n)".colorize(:yellow)
65
- when 'y'
66
- Launchy.open(feedback_url, options = {})
67
- when 'n'
68
- puts "Bye for now!"
69
- end
70
- else
71
- puts "### And this one?".colorize(:blue)
72
- puts
73
- puts ("title: ".colorize(:green) + "#{ds[1]["title"]}")
74
- puts ("description: ".colorize(:green) + "#{ds[1]["description"]}")
75
- puts ("publisher: ".colorize(:green) + "#{ds[1]["publisher"]}")
76
- puts ("temporal: ".colorize(:green) + "#{ds[1]["temporal"]}")
77
- puts ("spatial: ".colorize(:green) + "#{ds[1]["spatial"]}")
78
- puts ("created: ".colorize(:green) + "#{ds[1]["created"]}")
79
- puts ("updated: ".colorize(:green) + "#{ds[1]["updated"]}")
80
- puts ("score: ".colorize(:green) + "#{ds[1]["huntscore"]}")
24
+ if args[0].nil?
25
+ puts "usage: $ hunter find keyword [geo] [temp]"
26
+ elsif
27
+ url = Datahunter.datasets_url(args[0], args[1], args[2])
28
+
29
+ response = RestClient.get(url, :content_type => :json) do |response, request, result, &block|
30
+ elapsed_time = Time.now - start_time
31
+
32
+ case response.code
33
+ when 200
34
+ datasets = JSON.parse(response.body).reverse
35
+ puts "### Response in #{elapsed_time} seconds".colorize(:blue)
36
+
37
+ messages = [
38
+ "### Looks like we've got something for you!".colorize(:blue),
39
+ "### And this one?".colorize(:blue),
40
+ "### Last try...".colorize(:blue)
41
+ ]
42
+
43
+ 3.times do |index|
44
+ puts messages[index]
81
45
  puts
46
+ Datahunter.print_dataset_info datasets[index]
47
+
82
48
  case ask "### get the data? (y/n)".colorize(:yellow)
83
49
  when 'y'
84
- Launchy.open(ds[1]["uri"], options = {})
85
- when 'n'
86
- if ds[2].nil?
87
- puts ("Remember, this is a first prototype, there will surely be a lot more datasets indexed soon. If you want us to find a dataset for you, or if you just want to give us a feedback, don't hesitate!".colorize(:red))
88
- case ask "### give feedback? (y/n)".colorize(:yellow)
89
- when 'y'
90
- Launchy.open(feedback_url, options = {})
91
- when 'n'
92
- puts "Bye for now!"
93
- end
94
- else
95
- puts "### Last try...".colorize(:blue)
96
- puts
97
- puts ("title: ".colorize(:green) + "#{ds[2]["title"]}")
98
- puts ("description: ".colorize(:green) + "#{ds[2]["description"]}")
99
- puts ("publisher: ".colorize(:green) + "#{ds[2]["publisher"]}")
100
- puts ("temporal: ".colorize(:green) + "#{ds[2]["temporal"]}")
101
- puts ("spatial: ".colorize(:green) + "#{ds[2]["spatial"]}")
102
- puts ("created: ".colorize(:green) + "#{ds[2]["created"]}")
103
- puts ("updated: ".colorize(:green) + "#{ds[2]["updated"]}")
104
- puts ("score: ".colorize(:green) + "#{ds[2]["huntscore"]}")
105
- puts
106
- case ask "### get the data? (y/n)".colorize(:yellow)
107
- when 'y'
108
- Launchy.open(ds[2]["uri"], options = {})
109
- when 'n'
110
- puts ("You may want to try: ".colorize(:red) + "'$ hunter search #{tag}'".colorize(:blue))
111
- puts ("Remember, this is a first prototype, there will surely be a lot more datasets indexed soon. If you want us to find a dataset for you, or if you just want to give us a feedback, don't hesitate: ".colorize(:red))
112
- case ask "### give feedback? (y/n)".colorize(:yellow)
113
- when 'y'
114
- Launchy.open(feedback_url, options = {})
115
- when 'n'
116
- puts "Bye for now!"
117
- end
118
- end
50
+ Launchy.open(datasets[index]["uri"], options = {})
51
+ break
52
+ else # When no
53
+ if index == 2
54
+ puts ("You may want to try: ".colorize(:red) + "'$ hunter search #{args[0].downcase}'".colorize(:blue))
55
+ end
56
+ if index >= 2 or datasets[index+1].nil?
57
+ Datahunter.print_excuse_message
58
+ Datahunter.print_feedback_request
59
+ break
119
60
  end
120
61
  end
121
62
  end
63
+ when 500
64
+ puts "We've found nothing for your query: as every good hunter... we are still learning".colorize(:red)
65
+ Datahunter.print_excuse_message
66
+ Datahunter.print_feedback_request
67
+ else
68
+ response.return!(request, result, &block)
122
69
  end
123
- when 500
124
- puts "We've found nothing for your query: as every good hunter... we are still learning".colorize(:red)
125
- puts ("Remember, this is a first prototype, there will surely be a lot more datasets indexed soon. If you want us to find a dataset for you, or if you just want to give us a feedback, don't hesitate!".colorize(:red))
126
- case ask "### give feedback? (y/n)".colorize(:yellow)
127
- when 'y'
128
- Launchy.open(feedback_url, options = {})
129
- when 'n'
130
- puts "Bye for now!"
131
- end
132
- else
133
- response.return!(request, result, &block)
134
70
  end
135
- }
71
+ end
136
72
  end
137
73
  end
138
74
 
@@ -142,64 +78,44 @@ command :search do |c|
142
78
  c.description = c.summary
143
79
  c.example 'Search open data for population', 'hunter search population'
144
80
  c.action do |args, options|
145
- tag = args[0]
146
- geo = args[1]
147
- temp = args[2]
148
-
149
- tag = tag.downcase.split.first if tag
150
- geo = geo.downcase if geo
151
81
 
152
82
  start_time = Time.now
153
83
 
154
- if geo.nil? and temp.nil?
155
- url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}"
156
- elsif temp.nil?
157
- url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&spatial=#{geo}"
158
- elsif geo.nil?
159
- url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&temporal=#{temp}"
160
- else
161
- url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&spatial=#{geo}&temporal=#{temp}"
162
- end
84
+ url = Datahunter.datasets_url(args[0], args[1], args[2])
163
85
 
164
- response = RestClient.get(url, :content_type => :json){ |response, request, result, &block|
86
+ response = RestClient.get(url, :content_type => :json) do |response, request, result, &block|
165
87
 
166
88
  elapsed_time = Time.now - start_time
167
89
 
168
90
  case response.code
169
91
  when 200
170
- ds = JSON.parse(response.body).reverse
92
+ datasets = JSON.parse(response.body).reverse
171
93
  puts "### Response in #{elapsed_time} seconds".colorize(:blue)
172
- puts "### We've found #{ds.size} datasets corresponding to your query #{tag}:".colorize(:blue)
94
+ puts "### We've found #{datasets.size} datasets corresponding to your query #{args[0].downcase}:".colorize(:blue)
173
95
  puts
174
- ds.each do |result|
96
+ datasets.each do |result|
175
97
  puts ("#{result["title"]}".colorize(:green) + " (#{result["uri"]})")
176
98
  end
177
-
178
99
  when 500
179
- puts "We've found nothing for your query: as every good hunter... we are still learning".colorize(:red)
180
- puts ("Remember, this is a first prototype, there will surely be a lot more datasets indexed soon. If you want us to find a dataset for you, or if you just want to give us a feedback, don't hesitate!".colorize(:red))
181
- case ask "### give feedback? (y/n)".colorize(:yellow)
182
- when 'y'
183
- Launchy.open(feedback_url, options = {})
184
- when 'n'
185
- puts "Bye for now!"
186
- end
100
+ puts "We found nothing for your query: as every good hunter... we are still learning".colorize(:red)
101
+ Datahunter.print_excuse_message
102
+ Datahunter.print_feedback_request
187
103
  else
188
104
  response.return!(request, result, &block)
189
105
  end
190
- }
106
+ end
191
107
  end
192
108
  end
193
109
 
194
- command :hunter do |c|
195
- c.syntax = 'hunter hunter'
110
+ command :about do |c|
111
+ c.syntax = 'hunter about'
196
112
  c.summary = 'About Hunter'
197
113
  c.description = c.summary
198
114
  c.action do |args, options|
199
115
  puts "
200
- ...........888888888888888..............
116
+ ...........888888888888888..............
201
117
  ........8888888888888888888888..........
202
- .....88888888888888888888888888888......
118
+ .....88888888888888888888888888888......
203
119
  ....8888888888888888888888888888888.....
204
120
  ...888888888888888888888888888~88888?...
205
121
  ..88888...888888888888888888..+888888...
@@ -221,11 +137,6 @@ $.........:8...............888888888888.
221
137
  .... .....................:88..........
222
138
  ..... ...............8.............".colorize(:red)
223
139
  puts "### Hunter is still a prototype, please don't hesitate to help us make open datasets research better!".colorize(:blue)
224
- case ask "### give feedback? (y/n)".colorize(:yellow)
225
- when 'y'
226
- Launchy.open(feedback_url, options = {})
227
- when 'n'
228
- puts "Bye for now!"
229
- end
140
+ Datahunter.print_feedback_request
230
141
  end
231
142
  end
data/hunter.gif ADDED
Binary file
data/lib/datahunter.rb CHANGED
@@ -1,5 +1,5 @@
1
+ require "datahunter/base"
1
2
  require "datahunter/version"
2
3
 
3
4
  module Datahunter
4
- # Your code goes here...
5
5
  end
@@ -0,0 +1,49 @@
1
+ require 'colorize'
2
+ require 'launchy'
3
+
4
+ module Datahunter
5
+ DATASETS_URL = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/"
6
+ FEEDBACK_URL = "https://docs.google.com/forms/d/1yNzZjCCXvWHQCbWz4sx-nui3LafeeLcT7FF9T-vbKvw/viewform"
7
+
8
+ def self.datasets_url tag, geo=nil, temp=nil
9
+ tag = tag.downcase.split.first if tag
10
+ geo = geo.downcase if geo
11
+
12
+ if geo.nil? and temp.nil?
13
+ "#{DATASETS_URL}?tags=#{tag}"
14
+ elsif temp.nil?
15
+ "#{DATASETS_URL}?tags=#{tag}&spatial=#{geo}"
16
+ elsif geo.nil?
17
+ "#{DATASETS_URL}?tags=#{tag}&temporal=#{temp}"
18
+ else
19
+ "#{DATASETS_URL}?tags=#{tag}&spatial=#{geo}&temporal=#{temp}"
20
+ end
21
+ end
22
+
23
+ def self.print_dataset_info dataset
24
+ puts ("title: ".colorize(:green) + "#{dataset["title"]}")
25
+ puts ("description: ".colorize(:green) + "#{dataset["description"]}")
26
+ puts ("publisher: ".colorize(:green) + "#{dataset["publisher"]}")
27
+ puts ("temporal: ".colorize(:green) + "#{dataset["temporal"]}")
28
+ puts ("spatial: ".colorize(:green) + "#{dataset["spatial"]}")
29
+ puts ("created: ".colorize(:green) + "#{dataset["created"]}")
30
+ puts ("updated: ".colorize(:green) + "#{dataset["updated"]}")
31
+ puts ("score: ".colorize(:green) + "#{dataset["huntscore"]}")
32
+ puts
33
+ end
34
+
35
+ def self.print_feedback_request
36
+ case ask "### give feedback? (y/n)".colorize(:yellow)
37
+ when 'y'
38
+ Launchy.open(FEEDBACK_URL, options = {})
39
+ else
40
+ puts "Bye for now!"
41
+ end
42
+ end
43
+
44
+ def self.print_excuse_message
45
+ puts "Remember, this is a first prototype, there will surely be a lot more "\
46
+ "datasets indexed soon. If you want us to find a dataset for you, or "\
47
+ "if you just want to give us a feedback, don't hesitate!".colorize(:red)
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module Datahunter
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/logo.png ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datahunter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terpo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-30 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -123,8 +123,11 @@ files:
123
123
  - Rakefile
124
124
  - bin/hunter
125
125
  - datahunter.gemspec
126
+ - hunter.gif
126
127
  - lib/datahunter.rb
128
+ - lib/datahunter/base.rb
127
129
  - lib/datahunter/version.rb
130
+ - logo.png
128
131
  homepage: ''
129
132
  licenses:
130
133
  - MIT