fundamentus_data 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 092ab11b3f4033886da92443708d67f96728c4ef
4
- data.tar.gz: bbecfc85d129476fddebd24c9601a498975e9e97
2
+ SHA256:
3
+ metadata.gz: '09a9bccde7f9598a98341dfbb2a6225fe8635556f9e165da6539de40b430dafa'
4
+ data.tar.gz: 18f0437b4dcbc514da5e303c3d15cc9b7b54947e95bd0fea86c553378eaf48f1
5
5
  SHA512:
6
- metadata.gz: 072ff24f077a5e77a2e42eeb5c3be80a19fd2dcdfe2ecdbc573e14fd1ad7840be8a1b51465cd7f40843a6f4ce2544ed9d3b41f923496dbe445e7516254d8c5b7
7
- data.tar.gz: fe23d5336957c2ff16cbf8f800e52907f0295a328ab5b6ec84cd987b2d2dc6b5df3a68a550e83ce6652fa3592a6f446903ce28e54768fa25fecaa2f1a717dcb3
6
+ metadata.gz: c880ab4082e656af0e417bdd8261326fcea6c5569634b7200bc46b17cd67dbdb9654b19d9dcd0907a68615af119b32d0d8cf9b87f763fdf33d719910abd517fc
7
+ data.tar.gz: 7d7264361856485a3e0ef4e473ff5d14a03785e0851100af43618b89fa6d91747c85510d80389b2c726b57afb8f6994fa9de55b17d358f5c9c87a4eefe4a3f3b
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
- Gemfile.lock
2
- data/*
3
- !data/.keep
4
- test/output/*
5
- !test/output/.keep
1
+ *.gem
2
+ Gemfile.lock
3
+ data/*
4
+ !data/.keep
5
+ test/output/*
6
+ !test/output/.keep
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md CHANGED
@@ -1,61 +1,61 @@
1
- # What is this?
2
-
3
- Save stocks financial information from [fundamentus.com.br](http://www.fundamentus.com.br) in JSON format.
4
-
5
- Tags: bovespa, stock market, bolsa de valores, brasil, brazilian, ações
6
-
7
- # Status
8
-
9
- Currently only the fields specified in the following hash are being retrieved:
10
-
11
- LABEL_MAP = {
12
- :share_count => 'Nro. Ações',
13
- :market_cap => 'Valor de mercado',
14
- :last_processed => 'Últ balanço processado',
15
- :pl => 'P/L',
16
- :pvp => 'P/VP',
17
- :pebit => 'P/EBIT',
18
- :lpa => 'LPA',
19
- :vpa => 'VPA',
20
- :net_margin => 'Marg. Líquida',
21
- :net_debt => 'Dív. Líquida',
22
- :net_assets => 'Patrim. Líq',
23
- :yearly_net_income => 'Receita Líquida',
24
- :yearly_net_profit => 'Lucro Líquido',
25
- :quarterly_net_income => ['Receita Líquida', 2],
26
- :quarterly_net_profit => ['Lucro Líquido', 2]
27
- }
28
-
29
- # Installation
30
-
31
- gem install fundamentus_data
32
-
33
- # Usage
34
-
35
- require 'fundamentus_data'
36
-
37
- FundamentusData.save ['PETR4', 'BBDC4', 'PSSA3'], './data', :verbose => true
38
-
39
- # License
40
-
41
- The MIT License (MIT)
42
-
43
- Copyright (c) 2014 Vinicius Pinto
44
-
45
- Permission is hereby granted, free of charge, to any person obtaining a copy
46
- of this software and associated documentation files (the "Software"), to deal
47
- in the Software without restriction, including without limitation the rights
48
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49
- copies of the Software, and to permit persons to whom the Software is
50
- furnished to do so, subject to the following conditions:
51
-
52
- The above copyright notice and this permission notice shall be included in all
53
- copies or substantial portions of the Software.
54
-
55
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61
- SOFTWARE.
1
+ # What is this?
2
+
3
+ Save stocks financial information from [fundamentus.com.br](http://www.fundamentus.com.br) in JSON format.
4
+
5
+ Tags: bovespa, stock market, bolsa de valores, brasil, brazilian, ações
6
+
7
+ # Status
8
+
9
+ Currently only the fields specified in the following hash are being retrieved:
10
+
11
+ LABEL_MAP = {
12
+ :share_count => 'Nro. Ações',
13
+ :market_cap => 'Valor de mercado',
14
+ :last_processed => 'Últ balanço processado',
15
+ :pl => 'P/L',
16
+ :pvp => 'P/VP',
17
+ :pebit => 'P/EBIT',
18
+ :lpa => 'LPA',
19
+ :vpa => 'VPA',
20
+ :net_margin => 'Marg. Líquida',
21
+ :net_debt => 'Dív. Líquida',
22
+ :net_assets => 'Patrim. Líq',
23
+ :yearly_net_income => 'Receita Líquida',
24
+ :yearly_net_profit => 'Lucro Líquido',
25
+ :quarterly_net_income => ['Receita Líquida', 2],
26
+ :quarterly_net_profit => ['Lucro Líquido', 2]
27
+ }
28
+
29
+ # Installation
30
+
31
+ gem install fundamentus_data
32
+
33
+ # Usage
34
+
35
+ require 'fundamentus_data'
36
+
37
+ FundamentusData.save ['PETR4', 'BBDC4', 'PSSA3'], './data', :verbose => true
38
+
39
+ # License
40
+
41
+ The MIT License (MIT)
42
+
43
+ Copyright (c) 2014 Vinicius Pinto
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining a copy
46
+ of this software and associated documentation files (the "Software"), to deal
47
+ in the Software without restriction, including without limitation the rights
48
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49
+ copies of the Software, and to permit persons to whom the Software is
50
+ furnished to do so, subject to the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in all
53
+ copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61
+ SOFTWARE.
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
- require 'rake/testtask'
2
-
3
- Rake::TestTask.new do |t|
4
- t.pattern = "test/*_test.rb"
5
- end
6
-
7
- task :default => [:test]
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.pattern = "test/*_test.rb"
5
+ end
6
+
7
+ task :default => [:test]
@@ -1,15 +1,15 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'fundamentus_data'
3
- s.version = '0.1.0'
4
- s.license = 'MIT'
5
- s.summary = 'Save brazilian stock data from the Fundamentus site in JSON format'
6
- s.description = 'Fundamentus.com.br is a brazilian site that provides financial information about companies listed in Bovespa (the brazilian stock market). This gem can be used to save data from specified stocks in JSON format for later processing.'
7
- s.author = 'Vinicius Pinto'
8
- s.email = 'contact@codense.com'
9
- s.homepage = 'http://github.com/viniciuspinto/fundamentus'
10
- s.files = `git ls-files`.split("\n") | Dir.glob('fundamentus_data/**/*')
11
- s.test_files = `git ls-files -- test/*`.split("\n")
12
-
13
- s.add_dependency 'nokogiri', '~> 1.6'
14
- s.add_development_dependency 'minitest', '~> 5.5'
15
- end
1
+ Gem::Specification.new do |s|
2
+ s.name = 'fundamentus_data'
3
+ s.version = '0.1.2'
4
+ s.license = 'MIT'
5
+ s.summary = 'Save brazilian stock data from the Fundamentus site in JSON format'
6
+ s.description = 'Fundamentus.com.br is a brazilian site that provides financial information about companies listed in Bovespa (the brazilian stock market). This gem can be used to save data from specified stocks in JSON format for later processing.'
7
+ s.author = 'Vinicius Pinto'
8
+ s.email = 'contact@codense.com'
9
+ s.homepage = 'http://github.com/viniciuspinto/fundamentus'
10
+ s.files = `git ls-files`.split("\n") | Dir.glob('fundamentus_data/**/*')
11
+ s.test_files = `git ls-files -- test/*`.split("\n")
12
+
13
+ s.add_dependency 'nokogiri', '~> 1.6'
14
+ s.add_development_dependency 'minitest', '~> 5.5'
15
+ end
@@ -1,19 +1,20 @@
1
- require_relative './fundamentus_fetcher'
2
- require_relative './fundamentus_parser'
3
- require_relative './util/url_fetcher'
4
- require_relative './util/file_manager'
5
-
6
- class FundamentusData
7
- def self.save(stock_codes, destination_path, options = {})
8
- destination_path = File.expand_path(destination_path, Dir.pwd) + '/'
9
-
10
- html_fetcher = UrlFetcher.new(options)
11
- pages = FundamentusFetcher.new(html_fetcher, options).fetch(stock_codes)
12
- file_manager = FileManager.new(destination_path, options)
13
- parser = FundamentusParser.new(options)
14
-
15
- pages.each do |key, content|
16
- file_manager.save(key + '.json', parser.parse(content).to_json)
17
- end
18
- end
19
- end
1
+ require_relative './fundamentus_fetcher'
2
+ require_relative './fundamentus_parser'
3
+ require_relative './util/url_fetcher'
4
+ require_relative './util/file_manager'
5
+
6
+ class FundamentusData
7
+ def self.save(stock_codes, destination_path, options = {})
8
+ destination_path = File.expand_path(destination_path, Dir.pwd) + '/'
9
+
10
+ fetcher = options[:fetcher] || UrlFetcher.new(options)
11
+
12
+ file_manager = FileManager.new(destination_path, options)
13
+ parser = FundamentusParser.new(options)
14
+
15
+ pages = FundamentusFetcher.new(fetcher, options).fetch(stock_codes)
16
+ pages.each do |key, content|
17
+ file_manager.save(key + '.json', parser.parse(content).to_json)
18
+ end
19
+ end
20
+ end
@@ -1,25 +1,25 @@
1
- class FundamentusFetcher
2
-
3
- def initialize(fetcher, options = {})
4
- @fetcher = fetcher
5
- if options.has_key?(:verbose)
6
- @verbose = options[:verbose]
7
- end
8
- end
9
-
10
- def fetch(stock_codes)
11
- if not stock_codes.is_a?(Array)
12
- stock_codes = [stock_codes]
13
- end
14
- urls = {}
15
- stock_codes.each do |code|
16
- urls[code] = url_for code
17
- end
18
- return @fetcher.fetch(urls)
19
- end
20
-
21
- def url_for(code)
22
- 'http://www.fundamentus.com.br/detalhes.php?papel=' + code
23
- end
24
-
25
- end
1
+ class FundamentusFetcher
2
+
3
+ def initialize(fetcher, options = {})
4
+ @fetcher = fetcher
5
+ if options.has_key?(:verbose)
6
+ @verbose = options[:verbose]
7
+ end
8
+ end
9
+
10
+ def fetch(stock_codes)
11
+ if not stock_codes.is_a?(Array)
12
+ stock_codes = [stock_codes]
13
+ end
14
+ urls = {}
15
+ stock_codes.each do |code|
16
+ urls[code] = url_for code
17
+ end
18
+ return @fetcher.fetch(urls)
19
+ end
20
+
21
+ def url_for(code)
22
+ 'https://www.fundamentus.com.br/detalhes.php?papel=' + code
23
+ end
24
+
25
+ end
@@ -1,64 +1,64 @@
1
- require 'nokogiri'
2
-
3
- class FundamentusParser
4
-
5
- LABEL_MAP = {
6
- :share_count => 'Nro. Ações',
7
- :market_cap => 'Valor de mercado',
8
- :last_processed => 'Últ balanço processado',
9
- :pl => 'P/L',
10
- :pvp => 'P/VP',
11
- :pebit => 'P/EBIT',
12
- :lpa => 'LPA',
13
- :vpa => 'VPA',
14
- :net_margin => 'Marg. Líquida',
15
- :net_debt => 'Dív. Líquida',
16
- :net_assets => 'Patrim. Líq',
17
- :yearly_net_income => 'Receita Líquida',
18
- :yearly_net_profit => 'Lucro Líquido',
19
- :quarterly_net_income => ['Receita Líquida', 2],
20
- :quarterly_net_profit => ['Lucro Líquido', 2]
21
- }
22
-
23
- def initialize(options = {})
24
- if options.has_key?(:verbose)
25
- @verbose = options[:verbose]
26
- end
27
- end
28
-
29
- def parse(content)
30
- @doc = Nokogiri::HTML.parse(content)
31
- parsed = {}
32
- LABEL_MAP.each do |key, label|
33
- if label.is_a?(Array)
34
- parsed[key] = read_value_with_label(label[0], label[1])
35
- else
36
- parsed[key] = read_value_with_label(label)
37
- end
38
- end
39
- parsed
40
- end
41
-
42
- private
43
-
44
- def read_value_with_label(label, index = 1)
45
- label_td = find_td_with_label(label, index)
46
- if label_td
47
- data = label_td.next_element().css('span.txt').first.text.strip
48
- end
49
- end
50
-
51
- def find_td_with_label(label, index = 1)
52
- count = 0
53
- @doc.css('body.detalhes div.conteudo td span.txt').each do |item|
54
- if item.content.strip == label
55
- count += 1
56
- if count == index
57
- return item.parent()
58
- end
59
- end
60
- end
61
- nil
62
- end
63
-
64
- end
1
+ require 'nokogiri'
2
+
3
+ class FundamentusParser
4
+
5
+ LABEL_MAP = {
6
+ :share_count => 'Nro. Ações',
7
+ :market_cap => 'Valor de mercado',
8
+ :last_processed => 'Últ balanço processado',
9
+ :pl => 'P/L',
10
+ :pvp => 'P/VP',
11
+ :pebit => 'P/EBIT',
12
+ :lpa => 'LPA',
13
+ :vpa => 'VPA',
14
+ :net_margin => 'Marg. Líquida',
15
+ :net_debt => 'Dív. Líquida',
16
+ :net_assets => 'Patrim. Líq',
17
+ :yearly_net_income => 'Receita Líquida',
18
+ :yearly_net_profit => 'Lucro Líquido',
19
+ :quarterly_net_income => ['Receita Líquida', 2],
20
+ :quarterly_net_profit => ['Lucro Líquido', 2]
21
+ }
22
+
23
+ def initialize(options = {})
24
+ if options.has_key?(:verbose)
25
+ @verbose = options[:verbose]
26
+ end
27
+ end
28
+
29
+ def parse(content)
30
+ @doc = Nokogiri::HTML.parse(content)
31
+ parsed = {}
32
+ LABEL_MAP.each do |key, label|
33
+ if label.is_a?(Array)
34
+ parsed[key] = read_value_with_label(label[0], label[1])
35
+ else
36
+ parsed[key] = read_value_with_label(label)
37
+ end
38
+ end
39
+ parsed
40
+ end
41
+
42
+ private
43
+
44
+ def read_value_with_label(label, index = 1)
45
+ label_td = find_td_with_label(label, index)
46
+ if label_td
47
+ data = label_td.next_element().css('span.txt').first.text.strip
48
+ end
49
+ end
50
+
51
+ def find_td_with_label(label, index = 1)
52
+ count = 0
53
+ @doc.css('body.detalhes div.conteudo td span.txt').each do |item|
54
+ if item.content.strip == label
55
+ count += 1
56
+ if count == index
57
+ return item.parent()
58
+ end
59
+ end
60
+ end
61
+ nil
62
+ end
63
+
64
+ end
@@ -1,21 +1,21 @@
1
- require 'json'
2
-
3
- class FileManager
4
-
5
- def initialize(dir_path, options = {})
6
- @dir_path = dir_path
7
- if options.has_key?(:verbose)
8
- @verbose = options[:verbose]
9
- end
10
- end
11
-
12
- def save(file_name, content)
13
- if @verbose
14
- puts "Saving content of length #{content.size} to #{@dir_path + file_name}"
15
- end
16
- File.open(@dir_path + file_name, 'w') do |f|
17
- f.write(content)
18
- end
19
- end
20
-
21
- end
1
+ require 'json'
2
+
3
+ class FileManager
4
+
5
+ def initialize(dir_path, options = {})
6
+ @dir_path = dir_path
7
+ if options.has_key?(:verbose)
8
+ @verbose = options[:verbose]
9
+ end
10
+ end
11
+
12
+ def save(file_name, content)
13
+ if @verbose
14
+ puts "Saving content of length #{content.size} to #{@dir_path + file_name}"
15
+ end
16
+ File.open(@dir_path + file_name, 'w') do |f|
17
+ f.write(content)
18
+ end
19
+ end
20
+
21
+ end
@@ -1,29 +1,29 @@
1
- require 'open-uri'
2
-
3
- class UrlFetcher
4
-
5
- def initialize(options = {})
6
- if options.has_key?(:verbose)
7
- @verbose = options[:verbose]
8
- end
9
- end
10
-
11
- def fetch(urls)
12
- responses = {}
13
- urls.each do |key, url|
14
- if @verbose
15
- puts "Downloading #{key} from #{url}"
16
- end
17
- responses[key] = download(url)
18
- sleep(0.5)
19
- end
20
- responses
21
- end
22
-
23
- def download(url)
24
- open(url) do |f|
25
- f.read
26
- end
27
- end
28
-
29
- end
1
+ require 'open-uri'
2
+
3
+ class UrlFetcher
4
+
5
+ def initialize(options = {})
6
+ if options.has_key?(:verbose)
7
+ @verbose = options[:verbose]
8
+ end
9
+ end
10
+
11
+ def fetch(urls)
12
+ responses = {}
13
+ urls.each do |key, url|
14
+ if @verbose
15
+ puts "Downloading #{key} from #{url}"
16
+ end
17
+ responses[key] = download(url)
18
+ sleep(0.5)
19
+ end
20
+ responses
21
+ end
22
+
23
+ def download(url)
24
+ URI.open(url, "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0") do |f|
25
+ f.read
26
+ end
27
+ end
28
+
29
+ end
@@ -1 +1 @@
1
- require_relative './fundamentus_data/fundamentus_data.rb'
1
+ require_relative './fundamentus_data/fundamentus_data.rb'
data/test/config.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'minitest/autorun'
2
- require 'fundamentus_data'
3
- require_relative './lib/local_file_fetcher'
4
-
5
- TEST_DIR = File.expand_path('.', File.dirname(__FILE__)) + '/'
1
+ require 'minitest/autorun'
2
+ require 'fundamentus_data'
3
+ require_relative './lib/local_file_fetcher'
4
+
5
+ TEST_DIR = File.expand_path('.', File.dirname(__FILE__)) + '/'