dl_jusyo_jp 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +86 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/dl_jusyo_jp.gemspec +27 -0
- data/lib/dl_jusyo_jp.rb +7 -0
- data/lib/dl_jusyo_jp/download.rb +35 -0
- data/lib/dl_jusyo_jp/import.rb +21 -0
- data/lib/dl_jusyo_jp/version.rb +3 -0
- data/lib/generators/dl_jusyo_jp/install_generator.rb +29 -0
- data/lib/generators/dl_jusyo_jp/templates/initializers/dl_jusyo_jp.rb +4 -0
- data/lib/generators/dl_jusyo_jp/templates/migrations/create_jusyos.rb +38 -0
- data/lib/generators/dl_jusyo_jp/templates/models/jusyo_jp_address.rb +4 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca324a88e04666ea8732b3dc92db2aec653a51b3
|
4
|
+
data.tar.gz: 58362ae856bacccd522aa9c9e1d6e781da922fc8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e006c0ae2c3d5e78fcfd7f53c3ee869f6e6bb6acfd17006c850493bf2e92c5a49c9876c647cee1163318dabf373879ab51ba2ae733a5c8e950e6463d2cc8b22f
|
7
|
+
data.tar.gz: 1a8f445caaa0ac79b2d5f71511b3dcf7d3416add6340ce04dba0cc66dec1906196558dcf9c57812a4384a4f020eb320bd07948ffacf88b4a550baf34bbc8eb48
|
data/.gitignore
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
## Environment normalisation:
|
12
|
+
/.bundle
|
13
|
+
/vendor/bundle
|
14
|
+
|
15
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
16
|
+
.rvmrc
|
17
|
+
|
18
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
19
|
+
/vendor/assets/bower_components
|
20
|
+
*.bowerrc
|
21
|
+
bower.json
|
22
|
+
|
23
|
+
# Ignore pow environment settings
|
24
|
+
.powenv
|
25
|
+
|
26
|
+
### OSX ###
|
27
|
+
.DS_Store
|
28
|
+
.AppleDouble
|
29
|
+
.LSOverride
|
30
|
+
|
31
|
+
# Icon must end with two \r
|
32
|
+
Icon
|
33
|
+
|
34
|
+
|
35
|
+
# Thumbnails
|
36
|
+
._*
|
37
|
+
|
38
|
+
# Files that might appear in the root of a volume
|
39
|
+
.DocumentRevisions-V100
|
40
|
+
.fseventsd
|
41
|
+
.Spotlight-V100
|
42
|
+
.TemporaryItems
|
43
|
+
.Trashes
|
44
|
+
.VolumeIcon.icns
|
45
|
+
|
46
|
+
# Directories potentially created on remote AFP share
|
47
|
+
.AppleDB
|
48
|
+
.AppleDesktop
|
49
|
+
Network Trash Folder
|
50
|
+
Temporary Items
|
51
|
+
.apdisk
|
52
|
+
|
53
|
+
|
54
|
+
### Emacs ###
|
55
|
+
# -*- mode: gitignore; -*-
|
56
|
+
*~
|
57
|
+
\#*\#
|
58
|
+
/.emacs.desktop
|
59
|
+
/.emacs.desktop.lock
|
60
|
+
*.elc
|
61
|
+
auto-save-list
|
62
|
+
tramp
|
63
|
+
.\#*
|
64
|
+
|
65
|
+
# Org-mode
|
66
|
+
.org-id-locations
|
67
|
+
*_archive
|
68
|
+
|
69
|
+
# flymake-mode
|
70
|
+
*_flymake.*
|
71
|
+
|
72
|
+
# eshell files
|
73
|
+
/eshell/history
|
74
|
+
/eshell/lastdir
|
75
|
+
|
76
|
+
# elpa packages
|
77
|
+
/elpa/
|
78
|
+
|
79
|
+
# reftex files
|
80
|
+
*.rel
|
81
|
+
|
82
|
+
# AUCTeX auto folder
|
83
|
+
/auto/
|
84
|
+
|
85
|
+
# cask packages
|
86
|
+
.cask/
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 dongoon.INC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# DlJusyoJp
|
2
|
+
[住所.jp](http://jusyo.jp/index.html)様が提供している住所データをダウンロードし、ActiveRecordテーブルにインポートする処理をまとめてあります。
|
3
|
+
|
4
|
+
自分が複数のRails appで使い回すため、またダウンロードするファイルの形式やテーブルフォーマットが変わったとしても検知できるようにテストを書いたものです。
|
5
|
+
|
6
|
+
|
7
|
+
## 導入方法
|
8
|
+
|
9
|
+
Gemfileを追加して
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'dl_jusyo_jp'
|
13
|
+
```
|
14
|
+
|
15
|
+
bundleして
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
必要なファイルを生成します。
|
20
|
+
|
21
|
+
$ rails generate dl_jusyo_jp:install
|
22
|
+
|
23
|
+
## 使い方
|
24
|
+
|
25
|
+
初版としては、一括で全国の情報を生成したテーブルにインポートする機能だけです。
|
26
|
+
以下をrailsコンソールで実行すれば完了です。
|
27
|
+
```ruby
|
28
|
+
DlJusyoJp::Import.execute
|
29
|
+
```
|
30
|
+
|
31
|
+
ダウンロードするテーブル名は dl_jusyo_jps となっています。
|
32
|
+
気に入らない、変えたいというときは
|
33
|
+
config/initializers/dl_jusyo_jp.rb を書き換えてください。
|
34
|
+
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dongoon/dl_jusyo_jp.
|
39
|
+
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dl_jusyo_jp"
|
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/setup
ADDED
data/dl_jusyo_jp.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dl_jusyo_jp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dl_jusyo_jp"
|
8
|
+
spec.version = DlJusyoJp::VERSION
|
9
|
+
spec.authors = ["Yasuhiko Maeda"]
|
10
|
+
spec.email = ["y.maeda@dongoon.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{住所.jpから住所情報をダウンロードしてRailsで使いやすいようにする}
|
13
|
+
spec.description = %q{住所.jp<http://jusyo.jp/>が提供してくださっている住所情報をダウンロードしてモデルのデータとしてインポートするrakeを提供します}
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "sqlite3-ruby"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "rubyzip"
|
26
|
+
spec.add_runtime_dependency "activerecord"
|
27
|
+
end
|
data/lib/dl_jusyo_jp.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module DlJusyoJp
|
2
|
+
|
3
|
+
module Download
|
4
|
+
require 'open-uri'
|
5
|
+
require 'zip'
|
6
|
+
|
7
|
+
def self.csv
|
8
|
+
csv = Tempfile.new ['address', '.csv']
|
9
|
+
|
10
|
+
Zip::File.open(download_zip.path) do |z|
|
11
|
+
z.each do |entry|
|
12
|
+
z.extract(entry, csv.path){ true }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
csv
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.download_zip
|
20
|
+
tmpfile = Tempfile.new ['address', '.zip']
|
21
|
+
|
22
|
+
File.open(tmpfile.path, 'wb') do |local|
|
23
|
+
open(download_url, 'rb') do |jusyo_jp|
|
24
|
+
local.write(jusyo_jp.read)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
tmpfile
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.download_url
|
32
|
+
'http://jusyo.jp/downloads/new/csv/csv_zenkoku.zip'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DlJusyoJp
|
2
|
+
|
3
|
+
module Import
|
4
|
+
require 'csv'
|
5
|
+
|
6
|
+
def self.execute
|
7
|
+
CSV.foreach(Download.csv.path, encoding: "Shift_JIS:UTF-8", write_headers: false).each_slice(chunk_size) do |rows|
|
8
|
+
insert = "INSERT INTO #{DlJusyoJp::ADDRESS_DOWNLOAD_TABLE} VALUES "
|
9
|
+
values = rows.map do |row|
|
10
|
+
next unless row[0].match(/^\d+$/) # skip header
|
11
|
+
'(NULL,' + row.map{|col| "'#{col}'"}.join(',') + ')'
|
12
|
+
end.compact.join(',')
|
13
|
+
ActiveRecord::Base.connection.exec_insert("#{insert}#{values}", 'jusyo.jp bulk insert', [])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.chunk_size
|
18
|
+
1000
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module DlJusyoJp
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Creates migrations for ddress tables (download & your app use)."
|
7
|
+
class_option :orm
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.expand_path("../templates", __FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_initializer
|
14
|
+
template '../templates/initializers/dl_jusyo_jp.rb', 'config/initializers/dl_jusyo_jp.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_migrations
|
18
|
+
Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
|
19
|
+
name = File.basename(filepath)
|
20
|
+
to_path = 'db/migrate'
|
21
|
+
# TODO: something wrong...
|
22
|
+
if Dir.glob("#{to_path}/[0-9]*_*.rb").grep(/\d+_#{name}$/).blank?
|
23
|
+
template("migrations/#{name}", "#{to_path}/#{Time.zone.now.strftime('%Y%m%d%H%M%S')}_#{name}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class CreateJusyos < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table "#{DlJusyoJp::ADDRESS_DOWNLOAD_TABLE}" do |t|
|
4
|
+
t.string :address_code, limit: 9
|
5
|
+
t.string :prefecture_code, limit: 2
|
6
|
+
t.string :city_code, limit: 5
|
7
|
+
t.string :town_code, limit: 9
|
8
|
+
t.string :zip_code, limit: 8
|
9
|
+
t.string :is_place, limit: 1
|
10
|
+
t.string :is_deleted, limit: 1
|
11
|
+
t.string :prefecture_name
|
12
|
+
t.string :prefecture_name_kana
|
13
|
+
t.string :city_name
|
14
|
+
t.string :city_name_kana
|
15
|
+
t.string :town_name
|
16
|
+
t.string :town_name_kana
|
17
|
+
t.string :town_name_plus
|
18
|
+
t.string :kyoto_name
|
19
|
+
t.string :town_detail
|
20
|
+
t.string :town_detail_kana
|
21
|
+
t.string :memo
|
22
|
+
t.string :place_name
|
23
|
+
t.string :place_name_kana
|
24
|
+
t.string :place_address
|
25
|
+
t.string :new_address_code
|
26
|
+
end
|
27
|
+
|
28
|
+
add_index "#{DlJusyoJp::ADDRESS_DOWNLOAD_TABLE}", :address_code, name: 'i_address_code'
|
29
|
+
add_index "#{DlJusyoJp::ADDRESS_DOWNLOAD_TABLE}", :prefecture_code, name: 'i_prefecture_code'
|
30
|
+
add_index "#{DlJusyoJp::ADDRESS_DOWNLOAD_TABLE}", :city_code, name: 'i_city_code'
|
31
|
+
add_index "#{DlJusyoJp::ADDRESS_DOWNLOAD_TABLE}", :town_code, name: 'i_town_code'
|
32
|
+
add_index "#{DlJusyoJp::ADDRESS_DOWNLOAD_TABLE}", :zip_code, name: 'i_zip_code'
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.down
|
36
|
+
drop_table "#{DlJusyoJp::ADDRESS_DOWNLOAD_TABLE}"
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dl_jusyo_jp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yasuhiko Maeda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-06 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3-ruby
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubyzip
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: "住所.jp<http://jusyo.jp/>が提供してくださっている住所情報をダウンロードしてモデルのデータとしてインポートするrakeを提供します"
|
84
|
+
email:
|
85
|
+
- y.maeda@dongoon.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- dl_jusyo_jp.gemspec
|
100
|
+
- lib/dl_jusyo_jp.rb
|
101
|
+
- lib/dl_jusyo_jp/download.rb
|
102
|
+
- lib/dl_jusyo_jp/import.rb
|
103
|
+
- lib/dl_jusyo_jp/version.rb
|
104
|
+
- lib/generators/dl_jusyo_jp/install_generator.rb
|
105
|
+
- lib/generators/dl_jusyo_jp/templates/initializers/dl_jusyo_jp.rb
|
106
|
+
- lib/generators/dl_jusyo_jp/templates/migrations/create_jusyos.rb
|
107
|
+
- lib/generators/dl_jusyo_jp/templates/models/jusyo_jp_address.rb
|
108
|
+
homepage:
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.4.8
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: "住所.jpから住所情報をダウンロードしてRailsで使いやすいようにする"
|
132
|
+
test_files: []
|