edinet_code 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc53d559cbb61a54b519af445cca786037ac6fb9
4
+ data.tar.gz: 977e94752949a5d2de2afb8e9312b67343898030
5
+ SHA512:
6
+ metadata.gz: b6f51a1734ec21e9b492262f54fc614664e6529b24cc3e935c73abf5e759e706fd201e044d7e66f808725dc385c00b2d823ed2bd31177d331d1bdf1aa0565b97
7
+ data.tar.gz: 276be4980d4c1e8a8e01cdebac83f6c7efd7506ab35cda30f7b19ac26250a8d89a4b69b794d5455396160471cb642457381192258af0976ff0f718d43e9ae6c9
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in edinet_code.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 utahta
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,39 @@
1
+ # EdinetCode
2
+
3
+ EDINETからedinetコードリストを取得する
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'edinet_code'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install edinet_code
18
+
19
+ Use headless:
20
+
21
+ install xvfb
22
+
23
+ ## Usage
24
+
25
+ require "edinet_code"
26
+
27
+ EdinetCode.get
28
+
29
+ EdinetCode.get(false) # do not use headless
30
+
31
+ EdinetCode.get_code_exists
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/utahta/edinet_code/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'edinet_code/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "edinet_code"
8
+ spec.version = EdinetCode::VERSION
9
+ spec.authors = ["utahta"]
10
+ spec.email = ["labs.ninxit@gmail.com"]
11
+ spec.summary = %q{Get the edinet code list from EDINET}
12
+ spec.description = %q{Get the edinet code list from EDINET}
13
+ spec.homepage = "https://github.com/utahta/edinet_code"
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.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_dependency 'selenium-webdriver', '2.40.0'
26
+ spec.add_dependency 'headless', '1.0.1'
27
+ spec.add_dependency 'rubyzip', '1.1.2'
28
+ end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+ require "selenium-webdriver"
4
+ require "headless"
5
+ require "zip"
6
+ require "tmpdir"
7
+ require "date"
8
+ require "csv"
9
+
10
+ require "edinet_code/version"
11
+ require "edinet_code/exception"
12
+ require "edinet_code/archive"
13
+ require "edinet_code/downloader"
14
+ require "edinet_code/reader"
15
+
16
+ module EdinetCode
17
+ module_function
18
+
19
+ def get(headless=true)
20
+ download_dir = File.join(Dir.tmpdir, 'edinet_code')
21
+ download_path = File.join(download_dir, "Edinetcode_#{Date.today.strftime("%Y%m%d")}.zip") # ファイル名のフォーマットは変更できない...
22
+
23
+ if headless
24
+ Headless.ly do
25
+ Downloader.fetch(download_path)
26
+ end
27
+ else
28
+ Downloader.fetch(download_path)
29
+ end
30
+ uncompress_file_path = Archive.unzip(download_path)
31
+ Reader.csv(uncompress_file_path)
32
+ end
33
+
34
+ def get_code_exists(headless=true)
35
+ vals = get(headless)
36
+ vals.delete_if{|val| val.code == ""}
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+
3
+ module EdinetCode
4
+
5
+ class Archive
6
+ def self.unzip(compress_file_path)
7
+ return nil unless File.exists?(compress_file_path)
8
+ compress_dir = File.dirname(compress_file_path)
9
+ uncompress_file_path = nil
10
+ Zip::File.open(compress_file_path) do |zip_file|
11
+ zip_file.each do |entry|
12
+ if File.extname(entry.name) == ".csv"
13
+ uncompress_file_path = File.join(compress_dir, entry.name)
14
+ if File.exist?(uncompress_file_path)
15
+ puts "既に解凍済みです:#{uncompress_file_path}"
16
+ break
17
+ end
18
+ entry.extract(uncompress_file_path)
19
+ break
20
+ end
21
+ end
22
+ end
23
+ uncompress_file_path
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+
3
+ module EdinetCode
4
+
5
+ class Downloader
6
+ def self.fetch(download_path, wait_sec=300)
7
+ return true if File.exist?(download_path)
8
+ download_dir = File.expand_path(File.dirname(download_path))
9
+ # require Firefox
10
+ profile = Selenium::WebDriver::Firefox::Profile.new
11
+ profile['browser.download.folderList'] = 2
12
+ profile['browser.download.dir'] = download_dir
13
+ profile['browser.helperApps.neverAsk.saveToDisk'] = "application/octet-stream"
14
+ driver = Selenium::WebDriver.for :firefox, :profile => profile
15
+
16
+ driver.navigate.to 'https://disclosure.edinet-fsa.go.jp/E01EW/BLMainController.jsp?uji.bean=ee.bean.W1E62071.EEW1E62071Bean&uji.verb=W1E62071InitDisplay&TID=W1E62071&PID=W0EZ0001&SESSIONKEY=&lgKbn=2&dflg=0&iflg=0'
17
+ element = driver.find_element(:class, 'main_table_1').find_elements(:xpath, ".//a")[0]
18
+ element.click
19
+
20
+ # ダウンロードできたかどうか調べる
21
+ # ファイルができるまで何秒間か待機する...
22
+ wait_sec.times{|i|
23
+ break if File.exist?(download_path)
24
+ print "\rwaiting.#{"."*i}"
25
+ sleep 1
26
+ }
27
+ print "\n"
28
+ driver.quit
29
+
30
+ File.exist?(download_path)
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,6 @@
1
+ # coding:utf-8
2
+
3
+ module EdinetCode
4
+ class PropertyError < StandardError
5
+ end
6
+ end
@@ -0,0 +1,54 @@
1
+ # coding: utf-8
2
+
3
+ module EdinetCode
4
+
5
+ class Reader
6
+ class Result
7
+ PROPERTIES = [:edinet_code, :kind, :listed, :consolidated, :capital, :settling_day,
8
+ :submitter, :submitter_en, :submitter_kana, :location, :category, :code]
9
+ PROPERTIES.each do |prop|
10
+ attr_reader prop
11
+ end
12
+
13
+ def initialize(attr={})
14
+ attr.each do |key, value|
15
+ unless PROPERTIES.include?(key)
16
+ raise PropertyError, "#{key}: プロパティに存在しない名前です"
17
+ end
18
+ instance_variable_set("@#{key.to_s}", value)
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.csv(uncompress_file_path)
24
+ return nil unless File.exist?(uncompress_file_path)
25
+ vals = []
26
+ CSV.open(uncompress_file_path, 'r:cp932') do |csv|
27
+ # ヘッダ部分の2行飛ばす
28
+ 2.times{
29
+ csv.shift
30
+ }
31
+ csv.each do |row|
32
+ row.map!{|r| r.encode("utf-8")}
33
+ vals.push(Result.new(
34
+ edinet_code: row[0],
35
+ kind: row[1],
36
+ listed: row[2],
37
+ consolidated: row[3],
38
+ capital: row[4],
39
+ settling_day: row[5],
40
+ submitter: row[6],
41
+ submitter_en: row[7],
42
+ submitter_kana: row[8],
43
+ location: row[9],
44
+ category: row[10],
45
+ code: row[11]
46
+ ))
47
+ end
48
+ end
49
+ vals
50
+ end
51
+ end
52
+
53
+ end
54
+
@@ -0,0 +1,3 @@
1
+ module EdinetCode
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,58 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe EdinetCode do
5
+
6
+ describe EdinetCode::Downloader do
7
+ before(:all) do
8
+ @tmp_dir = File.join(Dir.tmpdir, "edinet_code_test")
9
+ @zip_path = File.join(@tmp_dir, "Edinetcode_#{Date.today.strftime("%Y%m%d")}.zip")
10
+ @file_path = File.join(@tmp_dir, "EdinetcodeDlInfo.csv")
11
+ end
12
+
13
+ it "ファイルがダウンロードできること" do
14
+ EdinetCode::Downloader.fetch(@zip_path)
15
+ expect(File.exists?(@zip_path)).to eq true
16
+ end
17
+
18
+ describe EdinetCode::Archive do
19
+ it "Zipが解凍できること" do
20
+ uncompress_file_path = EdinetCode::Archive.unzip(@zip_path)
21
+ expect(uncompress_file_path).to eq @file_path
22
+ end
23
+
24
+ describe EdinetCode::Reader do
25
+ it "CSVを読み込めること" do
26
+ vals = EdinetCode::Reader.csv(@file_path)
27
+ expect(vals.size).to be >= 3000
28
+ end
29
+
30
+ it "CSVで読み込んだデータが正しいこと" do
31
+ # とりあえず空じゃなければ良しとする
32
+ vals = EdinetCode::Reader.csv(@file_path)
33
+ result = vals[0]
34
+ expect(result.edinet_code).not_to eq ""
35
+ expect(result.kind).not_to eq ""
36
+ expect(result.listed).not_to eq ""
37
+ expect(result.consolidated).not_to eq ""
38
+ expect(result.capital).not_to eq ""
39
+ expect(result.settling_day).not_to eq ""
40
+ expect(result.submitter).not_to eq ""
41
+ expect(result.submitter_en).not_to eq ""
42
+ expect(result.submitter_kana).not_to eq ""
43
+ expect(result.location).not_to eq ""
44
+ expect(result.category).not_to eq ""
45
+ expect(result.code).not_to eq ""
46
+ end
47
+ end
48
+ end
49
+
50
+ after(:all) do
51
+ if File.exists?(@tmp_dir)
52
+ FileUtils.rm_r(@tmp_dir)
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+
@@ -0,0 +1,23 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+ require 'rspec'
10
+ require 'edinet_code'
11
+ require 'fileutils'
12
+
13
+ RSpec.configure do |config|
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run :focus
17
+
18
+ # Run specs in random order to surface order dependencies. If you find an
19
+ # order dependency and want to debug it, you can fix the order by providing
20
+ # the seed, which is printed after each run.
21
+ # --seed 1234
22
+ config.order = 'random'
23
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edinet_code
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - utahta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-18 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: rspec
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: selenium-webdriver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.40.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.40.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: headless
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubyzip
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.1.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.1.2
97
+ description: Get the edinet code list from EDINET
98
+ email:
99
+ - labs.ninxit@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - edinet_code.gemspec
111
+ - lib/edinet_code.rb
112
+ - lib/edinet_code/archive.rb
113
+ - lib/edinet_code/downloader.rb
114
+ - lib/edinet_code/exception.rb
115
+ - lib/edinet_code/reader.rb
116
+ - lib/edinet_code/version.rb
117
+ - spec/edinet_code_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/utahta/edinet_code
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Get the edinet code list from EDINET
143
+ test_files:
144
+ - spec/edinet_code_spec.rb
145
+ - spec/spec_helper.rb