dart_api 0.0.2

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: 6ac35b2ee91a715fc5a393322eba33498011b942
4
+ data.tar.gz: c8dfc0ce8eaea6003d2fb047bbb5c13f42599875
5
+ SHA512:
6
+ metadata.gz: 9734e173534e4be6442bb4483f5f7c4eefbf7a1ad14114dacefc23fd469817bb9b8e86bac1df4229c529edaf9bdc316d9b4015bd21ecc685e526c9b1e7628061
7
+ data.tar.gz: 7f7377beab161e5161d697e0afaf9cdcd6c8da5c867686bb619f9053b960aef40d9e91bc8d09db9281d12b2d481ea12c2223738af71da4f518e29bffb8043e81
data/.DS_Store ADDED
Binary file
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dart_api_helper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 pureugong
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,45 @@
1
+ # DartApi
2
+
3
+ dart_api gem을 활용하면 [dart 공식사이트](http://dart.fss.or.kr/)에서
4
+
5
+ 상장기업의 재무정보를 좀 더 쉽게 가져올 수 있습니다.
6
+
7
+ [dart 공식사이트](http://dart.fss.or.kr/)에서 auth key를 우선 발급받아야 합니다.
8
+
9
+ 현재 기업재무정보를 조회할 수 있는 화면의 url을 가져오는 것 까지만 지원을 하고 있으며,
10
+
11
+ 이후 재무상태표, 손익계산서, 현금흐름표의 정보만을 따로 가져오는 것을 지원할 예정입니다.
12
+
13
+ ## 설치
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'dart_api'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install dart_api
27
+
28
+ ## 사용법
29
+
30
+ 1. parser준비
31
+
32
+ parser = DartApi::ReportParser.new(auth)
33
+
34
+ 2. 회사코드를 입력하여 report parsing
35
+
36
+ parser.parse(code)
37
+
38
+ 3. 기업의 report 조회
39
+
40
+ parser.reports
41
+
42
+ 4. 해당 년도 재무정보 조회 url
43
+
44
+ parser.report(year).url
45
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ exec "irb -r dart_api -I ./lib"
10
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dart_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dart_api"
8
+ spec.version = DartApi::VERSION
9
+ spec.authors = ["pureugong"]
10
+ spec.email = ["pureugong@gmail.com"]
11
+ spec.summary = %q{It helps you parse data from dart website.}
12
+ spec.description = %q{It helps you parse data from dart website.}
13
+ spec.homepage = "https://github.com/pureugong/dart_api"
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
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ end
data/lib/.DS_Store ADDED
Binary file
data/lib/dart_api.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "dart_api/version"
2
+ require "dart_api/report"
3
+ require "dart_api/report_parser"
4
+
5
+ begin
6
+ require "pry"
7
+ rescue LoadError
8
+ end
9
+
10
+ module DartApi
11
+ # binding.pry
12
+ end
@@ -0,0 +1,77 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module DartApi
6
+ TYPES = ["재무상태표","손익계산서","현금흐름표"]
7
+ class Report
8
+ attr_reader :company_name, :company_code, :report_number, :year, :content, :reader_url, :url
9
+
10
+ def initialize(options)
11
+ @company_name, @company_code, @report_number = options.values_at("crp_nm", "crp_cd", "rcp_no")
12
+ @year = options["rcp_dt"][0..3].to_i - 1
13
+ # url
14
+ end
15
+
16
+ def dcm_no
17
+ generate unless @dcm_no
18
+ @dcm_no
19
+ end
20
+
21
+ def ele_id
22
+ generate unless @ele_id
23
+ @ele_id
24
+ end
25
+
26
+ def content
27
+ generate unless @content
28
+ @content
29
+ end
30
+
31
+ def reader_url
32
+ "http://dart.fss.or.kr/dsaf001/main.do?rcpNo=#{report_number}"
33
+ end
34
+
35
+ def url
36
+ generate unless @url
37
+ @url
38
+ end
39
+
40
+ def read(type)
41
+ result = Hash.new
42
+ content.search("table").each do |table|
43
+ read_table table
44
+ end
45
+ result
46
+ end
47
+
48
+ private
49
+ def generate
50
+ tmp_report = Nokogiri::HTML(open(reader_url))
51
+ tmp = tmp_report.search("#north > div.view_search > ul > li:nth-child(1) > a").attr("onclick").text
52
+ @dcm_no = tmp.split("'")[-2]
53
+
54
+ tmp_report = tmp_report.search(":contains('XI. 재무제표 등')").to_s || tmp_report.search(":contains('III. 재무에 관한 사항')").to_s
55
+
56
+ n = tmp_report.index('text: "XI. 재무제표 등",').to_i || tmp_report.index('text: "III. 재무에 관한 사항",').to_i
57
+ @ele_id = tmp_report[n+29..n+30]
58
+
59
+ @url = "http://dart.fss.or.kr/report/viewer.do?rcpNo=#{report_number}&dcmNo=#{dcm_no}&eleId=#{ele_id}&offset=0&length=1"
60
+ @content = Nokogiri::HTML(open(url))
61
+ end
62
+
63
+ def read_table(table)
64
+ title = table.search("tbody > tr:nth-child(1) > td").text.gsub(/\s+/, "")
65
+ if title.eql? TYPES[type-1] || "포괄#{TYPES[type-1]}"
66
+ table.next.next.search("tr").each do |tr|
67
+ name = tr.search("td:nth-child(1)").text.strip.gsub(/\A\p{Space}*/, '')
68
+ value = tr.search("td:nth-child(2)").text.strip.gsub(/\A\p{Space}*/, '').gsub(",", "")
69
+ if value.include? "("
70
+ value = value[1..-2].to_i * -1
71
+ end
72
+ result[name.split(".")[-1]] = value unless name.empty? || value.to_s.empty?
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,26 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+
4
+ module DartApi
5
+ class ReportParser
6
+ attr_reader :reports, :auth, :rpt_no, :dcmt_no, :code
7
+
8
+ def initialize(auth)
9
+ @auth = auth
10
+ end
11
+
12
+ def parse(code)
13
+ url = "http://dart.fss.or.kr/api/search.json?auth=#{auth}&fin_rpt=Y&crp_cd=#{code}&start_dt=20100101&bsn_tp=A001&page_set=100"
14
+ @code = code
15
+ @reports = JSON.parse(open(url).read)["list"].map do |r|
16
+ Report.new(r)
17
+ end
18
+ end
19
+
20
+ def report(year)
21
+ reports.find do |report|
22
+ report.year.eql? year
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module DartApi
2
+ VERSION = "0.0.2"
3
+ end
data/spec/.DS_Store ADDED
Binary file
@@ -0,0 +1,91 @@
1
+ require "dart_api"
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
54
+ # For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dart_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - pureugong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-03 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
+ - !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: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: It helps you parse data from dart website.
70
+ email:
71
+ - pureugong@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".DS_Store"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - dart_api_helper.gemspec
84
+ - lib/.DS_Store
85
+ - lib/dart_api.rb
86
+ - lib/dart_api/report.rb
87
+ - lib/dart_api/report_parser.rb
88
+ - lib/dart_api/version.rb
89
+ - spec/.DS_Store
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/pureugong/dart_api
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: It helps you parse data from dart website.
115
+ test_files:
116
+ - spec/.DS_Store
117
+ - spec/spec_helper.rb