datahunter 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b38856da0169625fff8b05d7f9ad32a442537a8c
4
+ data.tar.gz: 31754c807faa9b730517cdc2ffb81f8960b6cf5a
5
+ SHA512:
6
+ metadata.gz: 36da23960b65f6e824ac33464260be3138dd80773df351dcd15cad091950c7ba41309f02de271bd7b7d3e89d926b2844c06d7ddc89afeb3bca8c718692d9710d
7
+ data.tar.gz: d9ae452f416d295b83b9ff7707b5e036fdec244b5cfd7e711923f19ec691bad86c7a6ec4715110672f841d98013135b6266920f1ab40116dcf40d26172e0c2fd
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in datahunter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Terpo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Datahunter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
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
+ $ gem install datahunter
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/datahunter/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/hunter ADDED
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'datahunter'
4
+ require 'rubygems'
5
+ require 'json'
6
+ require 'commander/import'
7
+ require 'rest_client'
8
+ require 'launchy'
9
+ require 'colorize'
10
+
11
+ program :version, '0.0.1'
12
+ program :description, 'Find open data easily and quicker than ever'
13
+
14
+ command :find do |c|
15
+ c.syntax = 'hunter find keyword [spatial-coverage] [temporal-coverage]'
16
+ c.summary = 'Returns the 3 most popular (most reused, viewed, etc) datasets corresponding to the triple keyword, spatial-coverage and temporal-coverage'
17
+ c.description = c.summary
18
+ c.example 'Find open data for the U.S. population', 'hunter find population us'
19
+ c.action do |args, options|
20
+ tag = args[0]
21
+ geo = args[1]
22
+ temp = args[2]
23
+
24
+ tag = tag.downcase if tag
25
+ geo = geo.downcase if geo
26
+
27
+ start_time = Time.now
28
+
29
+ if geo.nil? and temp.nil?
30
+ url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}"
31
+ elsif temp.nil?
32
+ url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&spatial=#{geo}"
33
+ elsif geo.nil?
34
+ url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&temporal=#{temp}"
35
+ else
36
+ url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&spatial=#{geo}&temporal=#{temp}"
37
+ end
38
+
39
+ response = RestClient.get(url, :content_type => :json){ |response, request, result, &block|
40
+ elapsed_time = Time.now - start_time
41
+ case response.code
42
+ when 200
43
+ ds = JSON.parse(response.body).reverse
44
+ puts "### Response in #{elapsed_time} seconds".colorize(:blue)
45
+ puts "### Looks like we've got something for you!".colorize(:blue)
46
+ puts
47
+ puts ("title: ".colorize(:green) + "#{ds[0]["title"]}")
48
+ puts ("description: ".colorize(:green) + "#{ds[0]["description"]}")
49
+ puts ("publisher: ".colorize(:green) + "#{ds[0]["publisher"]}")
50
+ puts ("temporal: ".colorize(:green) + "#{ds[0]["temporal"]}")
51
+ puts ("spatial: ".colorize(:green) + "#{ds[0]["spatial"]}")
52
+ puts ("created: ".colorize(:green) + "#{ds[0]["created"]}")
53
+ puts ("updated: ".colorize(:green) + "#{ds[0]["updated"]}")
54
+ puts ("score: ".colorize(:green) + "#{ds[0]["huntscore"]}")
55
+ puts
56
+ case ask "### get the data? (y/n)".colorize(:yellow)
57
+ when 'y'
58
+ Launchy.open(ds[0]["uri"], options = {})
59
+ when 'n'
60
+ if ds[1].nil?
61
+ 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))
62
+ puts "nicolas@rawdatahunter.com".colorize(:blue)
63
+ else
64
+ puts "### And this one?".colorize(:blue)
65
+ puts
66
+ puts ("title: ".colorize(:green) + "#{ds[1]["title"]}")
67
+ puts ("description: ".colorize(:green) + "#{ds[1]["description"]}")
68
+ puts ("publisher: ".colorize(:green) + "#{ds[1]["publisher"]}")
69
+ puts ("temporal: ".colorize(:green) + "#{ds[1]["temporal"]}")
70
+ puts ("spatial: ".colorize(:green) + "#{ds[1]["spatial"]}")
71
+ puts ("created: ".colorize(:green) + "#{ds[1]["created"]}")
72
+ puts ("updated: ".colorize(:green) + "#{ds[1]["updated"]}")
73
+ puts ("score: ".colorize(:green) + "#{ds[1]["huntscore"]}")
74
+ puts
75
+ case ask "### get the data? (y/n)".colorize(:yellow)
76
+ when 'y'
77
+ Launchy.open(ds[1]["uri"], options = {})
78
+ when 'n'
79
+ if ds[2].nil?
80
+ 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))
81
+ puts "nicolas@rawdatahunter.com".colorize(:blue)
82
+ else
83
+ puts "### Last try...".colorize(:blue)
84
+ puts
85
+ puts ("title: ".colorize(:green) + "#{ds[2]["title"]}")
86
+ puts ("description: ".colorize(:green) + "#{ds[2]["description"]}")
87
+ puts ("publisher: ".colorize(:green) + "#{ds[2]["publisher"]}")
88
+ puts ("temporal: ".colorize(:green) + "#{ds[2]["temporal"]}")
89
+ puts ("spatial: ".colorize(:green) + "#{ds[2]["spatial"]}")
90
+ puts ("created: ".colorize(:green) + "#{ds[2]["created"]}")
91
+ puts ("updated: ".colorize(:green) + "#{ds[2]["updated"]}")
92
+ puts ("score: ".colorize(:green) + "#{ds[2]["huntscore"]}")
93
+ puts
94
+ case ask "### get the data? (y/n)".colorize(:yellow)
95
+ when 'y'
96
+ Launchy.open(ds[2]["uri"], options = {})
97
+ when 'n'
98
+ puts ("You may want to try: ".colorize(:red) + "'$ hunter search #{tag}'".colorize(:blue))
99
+ 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))
100
+ puts "nicolas@rawdatahunter.com".colorize(:blue)
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ when 500
107
+ puts "We've found nothing for your query: as every good hunter... we are still learning".colorize(:red)
108
+ 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))
109
+ puts "nicolas@rawdatahunter.com".colorize(:blue)
110
+ else
111
+ response.return!(request, result, &block)
112
+ end
113
+ }
114
+ end
115
+ end
116
+
117
+ command :search do |c|
118
+ c.syntax = 'hunter search keyword [spatial-coverage] [temporal-coverage]'
119
+ c.summary = 'Returns all the datasets corresponding to the query, sorted by popularity'
120
+ c.description = c.summary
121
+ c.example 'Search open data for population', 'hunter search population'
122
+ c.action do |args, options|
123
+ tag = args[0]
124
+ geo = args[1]
125
+ temp = args[2]
126
+
127
+ tag = tag.downcase if tag
128
+ geo = geo.downcase if geo
129
+
130
+ start_time = Time.now
131
+
132
+ if geo.nil? and temp.nil?
133
+ url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}"
134
+ elsif temp.nil?
135
+ url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&spatial=#{geo}"
136
+ elsif geo.nil?
137
+ url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&temporal=#{temp}"
138
+ else
139
+ url = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/?tags=#{tag}&spatial=#{geo}&temporal=#{temp}"
140
+ end
141
+
142
+ response = RestClient.get(url, :content_type => :json){ |response, request, result, &block|
143
+
144
+ elapsed_time = Time.now - start_time
145
+
146
+ case response.code
147
+ when 200
148
+ ds = JSON.parse(response.body).reverse
149
+ puts "### Response in #{elapsed_time} seconds".colorize(:blue)
150
+ puts "### We've found #{ds.size} datasets corresponding to your query #{tag}:".colorize(:blue)
151
+ puts
152
+ ds.each do |result|
153
+ puts ("#{result["title"]}".colorize(:green) + " (#{result["uri"]})")
154
+ end
155
+
156
+ when 500
157
+ puts "We've found nothing for your query: as every good hunter... we are still learning".colorize(:red)
158
+ 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))
159
+ puts "nicolas@rawdatahunter.com".colorize(:blue)
160
+ else
161
+ response.return!(request, result, &block)
162
+ end
163
+ }
164
+ end
165
+ end
166
+
167
+ command :hunter do |c|
168
+ c.syntax = 'hunter hunter'
169
+ c.summary = 'About Hunter'
170
+ c.description = c.summary
171
+ c.action do |args, options|
172
+ puts "
173
+ ...........888888888888888..............
174
+ ........8888888888888888888888..........
175
+ .....88888888888888888888888888888......
176
+ ....8888888888888888888888888888888.....
177
+ ...888888888888888888888888888~88888?...
178
+ ..88888...888888888888888888..+888888...
179
+ .888888.=....................O78888888..
180
+ ?888888.......................Z88888888.
181
+ 8888888.......................888888888.
182
+ 8888888.......................888888888.
183
+ 8888888:......8O.......88.....888888888.
184
+ 88......ZO.....8=.....Z8.....8888888888.
185
+ $.........:8...............888888888888.
186
+ ............8.............8888888888888.
187
+ ..............O.........:88888888888888.
188
+ ...............8........88888888888888..
189
+ ................O......8.......888888...
190
+ ................8.88.8.........=8887 ..
191
+ . ................8888...........?8.....
192
+ .. ...........................8888......
193
+ ... .........................888........
194
+ .... .....................:88..........
195
+ ..... ...............8.............".colorize(:red)
196
+ puts "### Hunter is still a prototype, please don't hesitate to help us make open datasets research better!".colorize(:blue)
197
+ case ask "### give feedback? (y/n)".colorize(:yellow)
198
+ when 'y'
199
+ Launchy.open("http://rawdatahunter.com/contact/", options = {})
200
+ when 'n'
201
+ puts "Bye for now!"
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'datahunter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "datahunter"
8
+ spec.version = Datahunter::VERSION
9
+ spec.authors = ["Terpo"]
10
+ spec.email = ["nicolas.terpolilli@gmail.com"]
11
+ spec.summary = %q{A Command Line Interface to find Open Datasets}
12
+ spec.description = %q{Command line interface to find open datasets via the Hunter API}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
data/lib/datahunter.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "datahunter/version"
2
+
3
+ module Datahunter
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Datahunter
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datahunter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Terpo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Command line interface to find open datasets via the Hunter API
42
+ email:
43
+ - nicolas.terpolilli@gmail.com
44
+ executables:
45
+ - hunter
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/hunter
55
+ - datahunter.gemspec
56
+ - lib/datahunter.rb
57
+ - lib/datahunter/version.rb
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.4
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A Command Line Interface to find Open Datasets
82
+ test_files: []