yahoo_market_calendar 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: 9cf06be7c0822e6de5b599106438af3b5f4b3ff7
4
+ data.tar.gz: 19f7dff5b879fefe5922bf701530c374ce903e53
5
+ SHA512:
6
+ metadata.gz: 55329c9175acff6cb0bc64c9407c09ebf54e54ed5d1ae1201e1cccdbd1e73163fd74560635a93ebb75ce934faca9dff84e95febdc6167e72b502f49aae09cf3e
7
+ data.tar.gz: c81a34890cbf7a55d742b7a40c31ca7dd16b3c1acdbc396bde32d3878b7a3965def628f10f6ef4fa2cf4b437f3a670932c21c5ed106fdacc25ea9de68db460f9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yahoo_market_calendar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 fughz
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,93 @@
1
+ # YahooMarketCalendar
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yahoo_market_calendar`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Build Status
6
+ [![Circle CI](https://circleci.com/gh/fughz/yahoo_market_calendar.svg?style=svg)](https://circleci.com/gh/fughz/yahoo_market_calendar)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'yahoo_market_calendar'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install yahoo_market_calendar
23
+
24
+ ## Usage
25
+
26
+ A simple example program:
27
+
28
+ ```ruby:example.rb
29
+ #!/usr/bin/env ruby
30
+ require 'date'
31
+ require 'yahoo_market_calendar'
32
+
33
+ client = YahooMarketCalendar::Client.new
34
+ day_events = client.get_market_events(date: Date.new(2015, 10, 30),
35
+ country_code: YahooMarketCalendar::CountryCode::ALL,
36
+ priority: YahooMarketCalendar::Priority::ALL)
37
+
38
+ day_events.each do |event|
39
+ puts "time: " + event.time + " name: " + event.name
40
+ puts " last: " + event.last_data +
41
+ " expectation: " + event.expectation_data +
42
+ " result: " + event.result_data
43
+ puts " priority: " + event.priority
44
+ puts " country_code: " + event.country_code
45
+ end
46
+ ```
47
+
48
+ Produces output as:
49
+
50
+ ```
51
+ ...
52
+
53
+ time: 06:45 name: 7-9月期 四半期失業率
54
+ last: 5.9% expectation: 6.0% result:
55
+ priority: 2
56
+ country_code: NZD
57
+ time: 08:50 name: 10月 マネタリーベース [前年同月比]
58
+ last: 35.1% expectation: result:
59
+ priority: 1
60
+ country_code: JPY
61
+ time: 09:30 name: 9月 小売売上高 [前月比]
62
+ last: 0.4% expectation: 0.4% result:
63
+ priority: 2
64
+ country_code: AUD
65
+ time: 09:30 name: 9月 貿易収支
66
+ last: -30.95億豪ドル expectation: -29.00億豪ドル result:
67
+ priority: 1
68
+ country_code: AUD
69
+ time: 10:45 name: 10月 Caixinサービス部門購買担当者景気指数(PMI)
70
+ last: 50.5 expectation: result:
71
+ priority: 2
72
+ country_code: CNY
73
+ time: 14:00 name: 10月 消費者態度指数・一般世帯
74
+ last: 40.6 expectation: 41.0 result:
75
+ priority: 1
76
+ country_code: JPY
77
+
78
+ ...
79
+ ```
80
+
81
+ ## Development
82
+
83
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
84
+
85
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
86
+
87
+ ## Contributing
88
+
89
+ 1. Fork it ( https://github.com/[my-github-username]/yahoo_market_calendar/fork )
90
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
91
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
92
+ 4. Push to the branch (`git push origin my-new-feature`)
93
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yahoo_market_calendar"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,11 @@
1
+ ## Customize the test machine
2
+ machine:
3
+
4
+ timezone:
5
+ Japan
6
+
7
+ # Version of ruby to use
8
+ ruby:
9
+ version:
10
+ 2.2.3
11
+
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ require 'date'
3
+ require 'yahoo_market_calendar'
4
+
5
+ client = YahooMarketCalendar::Client.new
6
+ day_events = client.get_market_events(date: Date.new(2015, 10, 30),
7
+ country_code: YahooMarketCalendar::CountryCode::ALL,
8
+ priority: YahooMarketCalendar::Priority::ALL)
9
+
10
+ day_events.each do |event|
11
+ puts "time: " + event.time + " name: " + event.name
12
+ puts " last: " + event.last_data +
13
+ " expectation: " + event.expectation_data +
14
+ " result: " + event.result_data
15
+ puts " priority: " + event.priority
16
+ puts " country_code: " + event.country_code
17
+ end
18
+
19
+
@@ -0,0 +1,15 @@
1
+ require "yahoo_market_calendar/version"
2
+
3
+ module YahooMarketCalendar
4
+
5
+ # Your code goes here...
6
+ def self.hello_pruby
7
+ p "hello pruby!!"
8
+ end
9
+ end
10
+
11
+ require 'yahoo_market_calendar/country_code'
12
+ require 'yahoo_market_calendar/priority'
13
+ require 'yahoo_market_calendar/event'
14
+ require 'yahoo_market_calendar/day_events'
15
+ require 'yahoo_market_calendar/client'
@@ -0,0 +1,116 @@
1
+ # coding: utf-8
2
+ require 'date'
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ class YahooMarketCalendar::Client
7
+
8
+ API_URL = 'http://info.finance.yahoo.co.jp/fx/marketcalendar/'
9
+
10
+ def get_market_events(date: Date.today, **options)
11
+ country_code = options[:country_code] || YahooMarketCalendar::CountryCode::ALL
12
+ priority = options[:priority] || YahooMarketCalendar::Priority::ALL
13
+
14
+ charset = nil
15
+ html = open(create_api_url(date, country_code, priority)) do |f|
16
+ charset = f.charset
17
+ f.read # read html text
18
+ end
19
+
20
+ doc = Nokogiri::HTML.parse(html, nil, charset)
21
+
22
+ day_events = nil
23
+
24
+ doc.xpath("//*[@id='main']/div[3]/table").each do |node|
25
+ node.css('tr').each do |row|
26
+ unless row.css('th.date').empty? then
27
+ parsed_date = get_event_date(date.year, row.css('th.date').inner_text)
28
+ if parsed_date === date
29
+ day_events = YahooMarketCalendar::DayEvents.new
30
+ day_events.date = parsed_date
31
+ elsif not day_events.nil?
32
+ # got all specified day event
33
+ return day_events
34
+ end
35
+ else
36
+ unless day_events.nil?
37
+ event = YahooMarketCalendar::Event.new
38
+ event.time = row.css('td.time').inner_text
39
+ event.name = row.css('td.event').inner_text
40
+ event.priority = get_priority(row.css('td.priority').css('span').attribute('class').value)
41
+ event.country_code = get_country_code(row.css('td.event').css('span').attribute('class').value)
42
+ event.last_data = row.css('td.last').inner_text
43
+ event.expectation_data = row.css('td.expectation').inner_text
44
+ event.result_data = row.css('td.result').inner_text
45
+ day_events << event
46
+ end
47
+ end
48
+ end
49
+ end
50
+ return day_events
51
+ end
52
+
53
+ private
54
+
55
+ def create_api_url(date, country_code, priority)
56
+ API_URL + "?d=" + date.strftime("%Y%m%d") + "&c=" + country_code + "&i=" + priority
57
+ end
58
+
59
+ def get_event_date(year, date_text)
60
+ /(\d+)\/(\d+)/ =~ date_text
61
+ month = $1.to_i
62
+ day = $2.to_i
63
+ Date.new(year, month, day)
64
+ end
65
+
66
+ def get_priority(priority_class_text)
67
+ /icoRating(\d+)/ =~ priority_class_text
68
+ case $1.to_i
69
+ when 1 then
70
+ YahooMarketCalendar::Priority::LOW
71
+ when 2 then
72
+ YahooMarketCalendar::Priority::MIDDLE
73
+ when 3 then
74
+ YahooMarketCalendar::Priority::HIGH
75
+ else
76
+ YahooMarketCalendar::Priority::UNKNOWN
77
+ end
78
+ end
79
+
80
+ def get_country_code(country_class_text)
81
+ /icon\d+ ico([a-zA-Z]+)\d+/ =~ country_class_text
82
+ case $1
83
+ when "Jpn" then
84
+ YahooMarketCalendar::CountryCode::JP
85
+ when "Usa" then
86
+ YahooMarketCalendar::CountryCode::US
87
+ when "Eu" then
88
+ YahooMarketCalendar::CountryCode::EUR
89
+ when "Ger" then
90
+ YahooMarketCalendar::CountryCode::DE
91
+ when "Fra" then
92
+ YahooMarketCalendar::CountryCode::FR
93
+ when "Gbr" then
94
+ YahooMarketCalendar::CountryCode::GB
95
+ when "Aus" then
96
+ YahooMarketCalendar::CountryCode::AU
97
+ when "Nzl" then
98
+ YahooMarketCalendar::CountryCode::NZ
99
+ when "Sui" then
100
+ YahooMarketCalendar::CountryCode::CH
101
+ when "Can" then
102
+ YahooMarketCalendar::CountryCode::CA
103
+ when "Rsa" then
104
+ YahooMarketCalendar::CountryCode::ZA
105
+ when "Sin" then
106
+ YahooMarketCalendar::CountryCode::SG
107
+ when "Hkg" then
108
+ YahooMarketCalendar::CountryCode::HK
109
+ when "Cnh" then
110
+ YahooMarketCalendar::CountryCode::CN
111
+ else
112
+ YahooMarketCalendar::CountryCode::UNKNOWN
113
+ end
114
+ end
115
+ end
116
+
@@ -0,0 +1,19 @@
1
+
2
+ module YahooMarketCalendar::CountryCode
3
+ ALL = "ALL"
4
+ JP = "JPY" # Japan
5
+ US = "USD" # United States
6
+ EUR = "EUR" # Euro
7
+ DE = "DEM" # Germany
8
+ FR = "FRF" # France
9
+ GB = "GBP" # United Kingdom
10
+ AU = "AUD" # Australia
11
+ NZ = "NZD" # New Zealand
12
+ CH = "CHF" # Switzerland
13
+ CA = "CAD" # Canada
14
+ ZA = "ZAR" # Republic of South Africa
15
+ SG = "SGD" # Republic of Singapore
16
+ HK = "HKD" # Hong Kong
17
+ CN = "CNY" # China
18
+ UNKNOWN = "unknown"
19
+ end
@@ -0,0 +1,23 @@
1
+ require 'date'
2
+
3
+ class YahooMarketCalendar::DayEvents
4
+ include Enumerable
5
+
6
+ attr_accessor :date, :events
7
+
8
+ def initialize
9
+ @date = Date.new
10
+ @events = []
11
+ end
12
+
13
+ def <<(event)
14
+ @events << event
15
+ end
16
+
17
+ def each
18
+ @events.each do |event|
19
+ yield event
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+
2
+
3
+ class YahooMarketCalendar::Event
4
+ attr_accessor :time, :name, :priority, :country_code, :last_data, :expectation_data, :result_data
5
+
6
+ def initialize
7
+ @time = String.new
8
+ @name = String.new
9
+ @priority = YahooMarketCalendar::Priority::ALL
10
+ @country_code = YahooMarketCalendar::CountryCode::ALL
11
+ @last_data = String.new
12
+ @expect_data = String.new
13
+ @result_data = String.new
14
+ end
15
+
16
+ end
@@ -0,0 +1,8 @@
1
+
2
+ module YahooMarketCalendar::Priority
3
+ ALL = "0"
4
+ LOW = "1"
5
+ MIDDLE = "2"
6
+ HIGH = "3"
7
+ UNKNOWN = "unknown"
8
+ end
@@ -0,0 +1,3 @@
1
+ module YahooMarketCalendar
2
+ VERSION = "0.0.1"
3
+ 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 'yahoo_market_calendar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yahoo_market_calendar"
8
+ spec.version = YahooMarketCalendar::VERSION
9
+ spec.authors = ["fughz"]
10
+ spec.email = ["fughz.h@gmail.com"]
11
+
12
+ spec.summary = "simple client of Yahoo! Finance Market Clendar(http://info.finance.yahoo.co.jp/fx/marketcalendar/)"
13
+ spec.homepage = "https://github.com/fughz/yahoo_market_calendar"
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_runtime_dependency "nokogiri"
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yahoo_market_calendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - fughz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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:
70
+ email:
71
+ - fughz.h@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - circle.yml
87
+ - example/example.rb
88
+ - lib/yahoo_market_calendar.rb
89
+ - lib/yahoo_market_calendar/client.rb
90
+ - lib/yahoo_market_calendar/country_code.rb
91
+ - lib/yahoo_market_calendar/day_events.rb
92
+ - lib/yahoo_market_calendar/event.rb
93
+ - lib/yahoo_market_calendar/priority.rb
94
+ - lib/yahoo_market_calendar/version.rb
95
+ - yahoo_market_calendar.gemspec
96
+ homepage: https://github.com/fughz/yahoo_market_calendar
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.5
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: simple client of Yahoo! Finance Market Clendar(http://info.finance.yahoo.co.jp/fx/marketcalendar/)
120
+ test_files: []