brazilian_financial_indexes 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e8633d0ad5f9923f232d7c3ac6b273524c26518
|
4
|
+
data.tar.gz: 44645337734fe36296cea66717274eef1c487674
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b163a6bfb6a1c965f887d98b36030019ffcd13e06e0eab23cb34960af2fd3cffa6cd16794442618be04e28a61dcb966ed07fa86747e44b7086daa118e3ce6659
|
7
|
+
data.tar.gz: 5d5e3644635ccaab4a43f68d0a45c483e4a452a0b26d81f460020372f6628dcb7f03269e6ab39d01dc482a545ea8eacfd5f06034b6e83c0360fd3c2dd98eecff
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BrazilianFinancialIndexes
|
2
|
+
class API
|
3
|
+
def initialize(config)
|
4
|
+
@config = config
|
5
|
+
uri = URI("#{config["url"]}/login")
|
6
|
+
response = Net::HTTP.post_form(uri,
|
7
|
+
"email" => config["login"],
|
8
|
+
"password" => config["password"])
|
9
|
+
attrs = JSON.parse(response.body)
|
10
|
+
@auth_token = attrs["auth_token"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(collection)
|
14
|
+
uri = URI("#{@config["url"]}/#{@config["post_path"]}")
|
15
|
+
response = Net::HTTP.post_form(
|
16
|
+
uri, auth_token: @auth_token, values: collection.to_json)
|
17
|
+
JSON.parse(response.body)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -4,32 +4,11 @@ module BrazilianFinancialIndexes
|
|
4
4
|
|
5
5
|
class Application
|
6
6
|
def self.run
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def self.create_file
|
13
|
-
prefix = RUBY_PLATFORM.match(/linux/) ? "wine" : ""
|
14
|
-
File.delete(OUTPUT) if File.exists?(OUTPUT)
|
15
|
-
system("#{prefix} #{INDEX_DOWNLOADER_BIN}")
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.parse_file
|
19
|
-
lines = File.readlines(OUTPUT).map do |line|
|
20
|
-
date = Date.parse(line[11..18])
|
21
|
-
value = parse_value(line)
|
22
|
-
OpenStruct.new(
|
23
|
-
id: line[0..5], complement: line[6..8], type: line[9..10],
|
24
|
-
date: date, group: line[19..20], code: line[21..45].strip,
|
25
|
-
value: value)
|
26
|
-
end.compact
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.parse_value(line)
|
30
|
-
value = BigDecimal.new(line[46..70])
|
31
|
-
precision = line[71..72].to_i
|
32
|
-
parsed_value = (value / (10 ** precision)).to_f
|
7
|
+
config = YAML.load_file("config.yml")
|
8
|
+
Input.create_file
|
9
|
+
values = Input.parse_file
|
10
|
+
api = API.new(config["brazilian_financial_indexes"])
|
11
|
+
api.post(values)
|
33
12
|
end
|
34
13
|
end
|
35
14
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module BrazilianFinancialIndexes
|
2
|
+
class Input
|
3
|
+
INDEX_DOWNLOADER_BIN = Pathname("bin/Download_Indices.exe").to_s
|
4
|
+
OUTPUT = "Indic.txt"
|
5
|
+
|
6
|
+
def self.create_file
|
7
|
+
prefix = RUBY_PLATFORM.match(/linux/) ? "wine" : ""
|
8
|
+
File.delete(OUTPUT) if File.exists?(OUTPUT)
|
9
|
+
system("#{prefix} #{INDEX_DOWNLOADER_BIN}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse_file
|
13
|
+
lines = File.readlines(OUTPUT).map do |line|
|
14
|
+
date = Date.parse(line[11..18])
|
15
|
+
value = parse_value(line)
|
16
|
+
{ date: date, importing_code: line[19..45].strip, value: value }
|
17
|
+
end.compact
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def self.parse_value(line)
|
22
|
+
value = BigDecimal.new(line[46..70])
|
23
|
+
precision = line[71..72].to_i
|
24
|
+
parsed_value = (value / (10 ** precision)).to_f
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brazilian_financial_indexes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adriano Bacha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Parses financial indicators from BMFBovespa
|
14
14
|
email:
|
@@ -23,7 +23,9 @@ files:
|
|
23
23
|
- bin/Indica.exe
|
24
24
|
- bin/brazilian_financial_indexes
|
25
25
|
- lib/brazilian_financial_indexes.rb
|
26
|
+
- lib/brazilian_financial_indexes/api.rb
|
26
27
|
- lib/brazilian_financial_indexes/application.rb
|
28
|
+
- lib/brazilian_financial_indexes/input.rb
|
27
29
|
- lib/brazilian_financial_indexes/version.rb
|
28
30
|
homepage: http://github.com/simplific/brazilian_financial_indexes
|
29
31
|
licenses: []
|