syachicky 0.1.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8cb7f129535c97635310fa99f4d04e3237f61283
4
+ data.tar.gz: 36e3ebba7771bf71c9065e59443db6f4b26e81c7
5
+ SHA512:
6
+ metadata.gz: 083af6a474cd35e06072c977619a683e692b463385fffda69ecc046003042307d81466dd0c7822f1ed8f80b7624145bccf159725e88116f197940ec0559fd8f3
7
+ data.tar.gz: 42c8c2da2b07259dc6d837eab5e316fb3355ac4aa580b0047d836ea00ca9fb3abaee99968540d0a3f6886de01957761be2860afeb3156cf20d2ba10bd35b0652
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in syachicky.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 matsu-chara
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,33 @@
1
+ # syachicky
2
+
3
+ sorry_yahoo_finance([https://github.com/gogotanaka/sorry_yahoo_finance]())をみたら思いついてしまったので勢いで書いた。反省しかない。
4
+
5
+ ## install
6
+ 0
7
+ gem install syachicky
8
+
9
+ 1
10
+ doSyachicky.rbに
11
+
12
+ ```ruby
13
+ require 'syachicky'
14
+
15
+ syachicky = Syachicky::Syachicky.new(<証券コードをここに>)
16
+ syachicky.dataUpdate()
17
+ syachicky.printData('#{syachiku["name"]}, 終値:#{syachiku["finish"]}')
18
+ ```
19
+
20
+ などと書く
21
+
22
+ 2
23
+ zloginに
24
+
25
+ ```zsh
26
+ [[ -f ~/syachicky/doSyachicky.rb ]] && ruby ~/syachicky/doSyachicky.rb
27
+ ```
28
+
29
+ を追加する
30
+
31
+
32
+ 以上でログイン時に御社株価その他もろもろが表示されます。
33
+ 取得は一日一回行います。
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module Syachicky
2
+ VERSION = "0.1.3"
3
+ end
data/lib/syachicky.rb ADDED
@@ -0,0 +1,81 @@
1
+ require "syachicky/version"
2
+ require "json"
3
+ require "pp"
4
+ require "active_support/all"
5
+ require "sorry_yahoo_finance"
6
+
7
+ module Syachicky
8
+ class Syachicky
9
+ def initialize(bland, date=Date.today-36.hour, maxCacheDays=365*3)
10
+ # 銘柄コード
11
+ @bland = bland.to_i
12
+
13
+ # 取得データ日
14
+ @day = date
15
+ @dayString = @day.strftime("%Y/%m/%d")
16
+
17
+ # データの保持期間
18
+ @maxCacheDays = maxCacheDays
19
+
20
+ # 最終日データ
21
+ @lastDayData = nil
22
+
23
+ # dataディレクトリ
24
+ @dataDir = File.expand_path(File.dirname(__FILE__)) + "/../data"
25
+ end
26
+
27
+ def dataUpdate
28
+ cleanupIfDataOverThreshold()
29
+ writeBlandData() unless isGotToday()
30
+ end
31
+
32
+ # foramt => '社名:#{syachiku["code"]}, 終値:#{syachiku["finish"]}'
33
+ def printData(format=nil)
34
+ return unless @lastDayData
35
+
36
+ if format
37
+ syachiku = @lastDayData
38
+ puts eval('"' + format + '"')
39
+ else
40
+ pp @lastDayData
41
+ end
42
+
43
+ end
44
+
45
+ def getData(format=nil)
46
+ return @lastDayData
47
+ end
48
+
49
+ private
50
+ def isGotToday
51
+ return false unless File.exist?("#{@dataDir}/#{@bland}")
52
+
53
+ open("|tail -n 1 < #{@dataDir}/#{@bland}"){|file|
54
+ data = file.gets()
55
+ @lastDayData = JSON.parse(data) if data
56
+ result = @lastDayData["date"] if @lastDayData
57
+ return (@dayString == result)
58
+ }
59
+ end
60
+
61
+ def cleanupIfDataOverThreshold
62
+ return unless File.exist?("#{@dataDir}/#{@bland}")
63
+
64
+ open("|wc -l < #{@dataDir}/#{@bland}"){|file|
65
+ lines = file.gets().to_i
66
+ File.unlink("#{@dataDir}/#{@bland}") if lines > @maxCacheDays
67
+ }
68
+ end
69
+
70
+ def writeBlandData
71
+ info = SorryYahooFinance::GET(@bland, @day).values.stringify_keys!
72
+ info["date"] = @dayString
73
+ @lastDayData = info
74
+
75
+ Dir.mkdir("#{@dataDir}") unless Dir.exist?("#{@dataDir}")
76
+ File.open("#{@dataDir}/#{@bland}", "a"){|file|
77
+ file.puts(@lastDayData.to_json)
78
+ }
79
+ end
80
+ end
81
+ end
data/syachicky.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'syachicky/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "syachicky"
8
+ spec.version = Syachicky::VERSION
9
+ spec.authors = ["matsu-chara"]
10
+ spec.email = ["matsuy00@gmail.com"]
11
+ spec.summary = %q{stock price printer}
12
+ spec.description = %q{a stock price printer for all syachikus}
13
+ spec.homepage = "https://github.com/matsu-chara/syachicky"
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", "~> 10.3"
23
+
24
+ spec.add_dependency "json", "~> 1.8"
25
+ spec.add_dependency "activesupport", "~> 4.1"
26
+ spec.add_dependency "sorry_yahoo_finance", "~> 0.3"
27
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syachicky
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - matsu-chara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-22 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: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sorry_yahoo_finance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.3'
83
+ description: a stock price printer for all syachikus
84
+ email:
85
+ - matsuy00@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/syachicky.rb
96
+ - lib/syachicky/version.rb
97
+ - syachicky.gemspec
98
+ homepage: https://github.com/matsu-chara/syachicky
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.2.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: stock price printer
122
+ test_files: []