heydan 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Guardfile +44 -0
- data/LICENSE.txt +11 -0
- data/README.md +84 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/heydan +11 -0
- data/bin/setup +7 -0
- data/heydan.gemspec +49 -0
- data/lib/heydan.rb +65 -0
- data/lib/heydan/base.rb +72 -0
- data/lib/heydan/cdn.rb +30 -0
- data/lib/heydan/cli.rb +80 -0
- data/lib/heydan/help_text.rb +83 -0
- data/lib/heydan/helper.rb +108 -0
- data/lib/heydan/import.rb +49 -0
- data/lib/heydan/jurisdiction_file.rb +119 -0
- data/lib/heydan/open_civic_identifiers.rb +51 -0
- data/lib/heydan/script.rb +179 -0
- data/lib/heydan/script_file.rb +44 -0
- data/lib/heydan/server.rb +55 -0
- data/lib/heydan/source_file.rb +79 -0
- data/lib/heydan/sources.rb +128 -0
- data/lib/heydan/version.rb +3 -0
- data/lib/templates/script.rb.erb +32 -0
- metadata +285 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1ee89c19c81cd1085881148d715aebb67e5feff2
|
4
|
+
data.tar.gz: d9b8fd855f3ad595247b2bbe0310ea1f94921cd9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 86f5aab602eed69e4c1efb59950f54c07e25aa17ee3fadef6fc21ea5205ef3246cf029de5f9152d70700040140278b69352eb49cfdee60329b37b56b81f878e0
|
7
|
+
data.tar.gz: e78c0d64a5356e56dd5779c2d680ee2cc7211fca18dd9ffc66643aaaaad3dd64da9c2dc9526f17b50e3da61992083c19907f07e973aef7367713e3cd744e4205
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
28
|
+
require "guard/rspec/dsl"
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
|
43
|
+
|
44
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Dan Melton
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
6
|
+
furnished to do so, subject to the following conditions:
|
7
|
+
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
9
|
+
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
11
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# HeyDan
|
2
|
+
|
3
|
+
Why HeyDan? I wrote it to help answer questions. Every time you have a question about governments, I imagine you turning around and saying 'Hey Dan! how many governments have x or y?''
|
4
|
+
|
5
|
+
At every civic company I've worked at, I needed to build some sort of government data munging tool set. I wrote HeyDan, partly for myself, and partly to share.
|
6
|
+
|
7
|
+
The goal is to create an easy versino controlled data import and processing tool for single variables, attributes, properties, etc and an ultra fast http server backed by ElasticSearch with extreme filter capabilities and data extendability. This is not a data catalogue, its middleware to pull data from data catalogues and process it.
|
8
|
+
|
9
|
+
##Build Status
|
10
|
+
|
11
|
+
[![Build Status](https://travis-ci.org/danmelton/heydan.svg?branch=master)](https://travis-ci.org/danmelton/heydan)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
You will need git, ruby and elastic search
|
16
|
+
|
17
|
+
$ gem install heydan
|
18
|
+
|
19
|
+
## Command Line Usage
|
20
|
+
|
21
|
+
HeyDan is meant to be used in a shell:
|
22
|
+
|
23
|
+
$ heydan help
|
24
|
+
#returns a list of commands you do
|
25
|
+
|
26
|
+
$ heydan setup
|
27
|
+
#sets up heydan in the current directory
|
28
|
+
|
29
|
+
$ heydan build --type optional
|
30
|
+
#creates the jurisdiction files in the jurisdictions folder
|
31
|
+
|
32
|
+
$ heydan sources sync
|
33
|
+
#pulls down sources into sources folder leveraging git
|
34
|
+
|
35
|
+
$ heydan sources build
|
36
|
+
#builds through each source in the sources folder, optional parameters
|
37
|
+
#include --fromsource, --type, and FOLDER NAME VARIABLE
|
38
|
+
|
39
|
+
$ heydan sources add github_http_link.git
|
40
|
+
#clones a source from git repo and adds to settings file under sources
|
41
|
+
|
42
|
+
$heydan sources new FOLDER SOURCENAME VARIABLE
|
43
|
+
#creates or adds a new variable under sources/folder/sourcename and sources/folder/scripts/sourcenamevariable.rb
|
44
|
+
|
45
|
+
$ heydan import
|
46
|
+
#bulk imports the jurisdictions folder into elasticsearch for extreme search goodness
|
47
|
+
|
48
|
+
$ heydan server
|
49
|
+
#starts a sinatra server at localhost:4567/entities
|
50
|
+
|
51
|
+
$ heydan upload
|
52
|
+
#uploads contents of the datasets folder to aws as specified in the settings file.
|
53
|
+
|
54
|
+
## Adding Data
|
55
|
+
|
56
|
+
You can contribute to HeyDan by creating a new source folder on github. Look at https://github.com/danmelton/heydan_sources as an example.
|
57
|
+
|
58
|
+
To create a new directory for data:
|
59
|
+
|
60
|
+
$ heydan sources new example example_source example_variable_name
|
61
|
+
|
62
|
+
This will create a folder 'example' in sources/ with a json file name example_source and a ruby file inside example/script/example_variable_name.rb
|
63
|
+
|
64
|
+
You can update json file with metadata about the source. Each variable also has metadata too.
|
65
|
+
|
66
|
+
The script file has three methods in it. A version, which defaults to 1; a type, which defaults to 'dataset'; and a build method with some sample code.
|
67
|
+
|
68
|
+
At the end of the build method, you should have a 2 to multiple column @data variable with the first row as headers.
|
69
|
+
|
70
|
+
You can add pry in the build method to help you troubleshoot:
|
71
|
+
|
72
|
+
require 'pry'
|
73
|
+
binding.pry
|
74
|
+
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on [GitHub Issues](https://github.com/danmelton/heydan/issues). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
79
|
+
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
84
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "heydan"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/heydan
ADDED
data/bin/setup
ADDED
data/heydan.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'heydan/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "heydan"
|
8
|
+
spec.version = HeyDan::VERSION
|
9
|
+
spec.authors = ["Dan Melton"]
|
10
|
+
spec.email = ["melton.dan@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{HeyDan munges data for jurisdictions}
|
13
|
+
spec.description = %q{Use HeyDan to download, munge and manage data for jurisdictions}
|
14
|
+
spec.homepage = "http://github.com/danmelton/heydan"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "bin"
|
27
|
+
spec.executables = ['heydan']
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
#depedencies
|
31
|
+
spec.add_dependency "thor", "~> 0.19"
|
32
|
+
spec.add_dependency "rubyzip", "~>1.1"
|
33
|
+
spec.add_dependency "git", "~>1.2"
|
34
|
+
spec.add_dependency "pry", "~> 0.10"
|
35
|
+
spec.add_dependency "ruby-progressbar","~>1.7"
|
36
|
+
spec.add_dependency "elasticsearch","~>1.0"
|
37
|
+
spec.add_dependency "sinatra","~>1.4"
|
38
|
+
spec.add_dependency "sinatra-cross_origin","~>0.3"
|
39
|
+
spec.add_dependency "fog-aws", "~>0.7.5"
|
40
|
+
|
41
|
+
#development/test depedencies
|
42
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
43
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
44
|
+
spec.add_development_dependency "rspec"
|
45
|
+
|
46
|
+
spec.add_development_dependency "guard-rspec"
|
47
|
+
spec.add_development_dependency "vcr"
|
48
|
+
spec.add_development_dependency "webmock"
|
49
|
+
end
|
data/lib/heydan.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
module HeyDan
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :help
|
6
|
+
attr_accessor :folders
|
7
|
+
attr_accessor :sources
|
8
|
+
attr_accessor :settings_file
|
9
|
+
attr_accessor :cdn
|
10
|
+
attr_accessor :options
|
11
|
+
attr_accessor :elasticsearch
|
12
|
+
attr_accessor :aws_access_id
|
13
|
+
attr_accessor :aws_secret_key
|
14
|
+
attr_accessor :aws_bucket
|
15
|
+
attr_accessor :aws_region
|
16
|
+
|
17
|
+
#calls help text when needed
|
18
|
+
def helper_text(method)
|
19
|
+
if self.help
|
20
|
+
HeyDan::HelpText.send(method)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
self.settings_file = nil
|
26
|
+
|
27
|
+
self.help = true
|
28
|
+
|
29
|
+
def self.help?
|
30
|
+
self.help
|
31
|
+
end
|
32
|
+
|
33
|
+
self.folders ||= {
|
34
|
+
jurisdictions: 'jurisdictions',
|
35
|
+
sources: 'sources',
|
36
|
+
downloads: 'downloads',
|
37
|
+
datasets: 'datasets'
|
38
|
+
}
|
39
|
+
|
40
|
+
self.sources = {
|
41
|
+
heydan_sources: 'https://github.com/danmelton/heydan_sources.git'
|
42
|
+
}
|
43
|
+
|
44
|
+
self.cdn = 'https://heydan.s3-us-west-1.amazonaws.com'
|
45
|
+
|
46
|
+
self.options = {}
|
47
|
+
self.elasticsearch = {url: 'http://localhost:9200'}
|
48
|
+
end
|
49
|
+
|
50
|
+
require_relative "heydan/version"
|
51
|
+
require_relative "heydan/base"
|
52
|
+
require_relative "heydan/help_text"
|
53
|
+
require_relative "heydan/helper"
|
54
|
+
require_relative "heydan/script"
|
55
|
+
require_relative "heydan/script_file"
|
56
|
+
require_relative "heydan/source_file"
|
57
|
+
require_relative "heydan/jurisdiction_file"
|
58
|
+
require_relative "heydan/open_civic_identifiers"
|
59
|
+
require_relative "heydan/sources"
|
60
|
+
require_relative "heydan/import"
|
61
|
+
require_relative "heydan/server"
|
62
|
+
require_relative "heydan/cdn"
|
63
|
+
require_relative "heydan/cli"
|
64
|
+
|
65
|
+
HeyDan::Base.load_or_create_settings
|
data/lib/heydan/base.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
class HeyDan::Base
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def setup(dir=nil)
|
6
|
+
setup_dir(dir) if dir
|
7
|
+
dir ||= Dir.pwd
|
8
|
+
load_or_create_settings dir
|
9
|
+
create_folders
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_folders
|
13
|
+
HeyDan::folders.keys.each do |folder|
|
14
|
+
path = HeyDan::folders[folder]
|
15
|
+
FileUtils.mkdir_p path if !Dir.exist?(path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_or_create_settings(dir=nil)
|
20
|
+
dir ||= Dir.pwd
|
21
|
+
HeyDan.settings_file ||= if ENV['HEYDAN_SETTINGS']
|
22
|
+
ENV['HEYDAN_SETTINGS']
|
23
|
+
else
|
24
|
+
File.join(dir, 'heydan_settings.yml')
|
25
|
+
end
|
26
|
+
return load_settings_file(HeyDan.settings_file) if File.exist?(HeyDan.settings_file)
|
27
|
+
create_settings_file(dir)
|
28
|
+
HeyDan.settings_file
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_settings_file(settings_file)
|
32
|
+
settings = YAML.load(File.read(settings_file))
|
33
|
+
settings.keys.each do |key|
|
34
|
+
method = key.to_s + '='
|
35
|
+
HeyDan.send(method, settings[key]) if HeyDan.respond_to?(method)
|
36
|
+
end
|
37
|
+
HeyDan.settings_file = settings_file
|
38
|
+
end
|
39
|
+
|
40
|
+
def save_settings(settings_file=nil)
|
41
|
+
settings_file ||= HeyDan.settings_file
|
42
|
+
File.open(settings_file, 'w') do |f|
|
43
|
+
f.write({help: HeyDan.help,
|
44
|
+
folders: HeyDan.folders,
|
45
|
+
sources: HeyDan.sources,
|
46
|
+
elasticsearch: {url: 'http://localhost:9200'}
|
47
|
+
}.to_yaml)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_settings_file(dir)
|
52
|
+
setup_dir(dir)
|
53
|
+
setup_folders(dir)
|
54
|
+
settings_file = File.join(dir, 'heydan_settings.yml')
|
55
|
+
save_settings(settings_file)
|
56
|
+
end
|
57
|
+
|
58
|
+
def setup_dir(dir)
|
59
|
+
if !Dir.exist?(dir)
|
60
|
+
FileUtils.mkdir_p(dir)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def setup_folders(dir)
|
65
|
+
HeyDan::folders.keys.each do |folder|
|
66
|
+
HeyDan::folders[folder] = File.join(dir,HeyDan::folders[folder])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/lib/heydan/cdn.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class HeyDan::Cdn
|
2
|
+
|
3
|
+
#Upload files from the Downloads folder
|
4
|
+
def self.upload(names=[])
|
5
|
+
require 'fog/aws'
|
6
|
+
@connection = Fog::Storage.new({
|
7
|
+
provider: 'AWS',
|
8
|
+
region: HeyDan.aws_region,
|
9
|
+
aws_access_key_id: HeyDan.aws_access_id,
|
10
|
+
aws_secret_access_key: HeyDan.aws_secret_key
|
11
|
+
})
|
12
|
+
@directory = @connection.directories.get(HeyDan.aws_bucket)
|
13
|
+
if names.size == 0
|
14
|
+
files = Dir.glob("#{HeyDan.folders[:datasets]}/*.csv")
|
15
|
+
else
|
16
|
+
files = names.map { |f| File.join(HeyDan.folders[:datasets], "#{f}.csv")}
|
17
|
+
end
|
18
|
+
files.each do |f|
|
19
|
+
name = f.gsub("#{HeyDan.folders[:datasets]}/", '')
|
20
|
+
puts "uploading #{name}"
|
21
|
+
file = @directory.files.new({
|
22
|
+
:key => name,
|
23
|
+
:body => File.open(f, 'r'),
|
24
|
+
:public => true
|
25
|
+
})
|
26
|
+
file.save
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|