mizuho_bank 0.1.0 → 0.1.1

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.
Files changed (5) hide show
  1. data/README.rdoc +32 -14
  2. data/VERSION +1 -1
  3. data/lib/mizuho_bank.rb +81 -22
  4. metadata +2 -3
  5. data/readme.txt +0 -19
@@ -1,18 +1,36 @@
1
- = mizuho_bank
1
+ = mizuho_bank : みずほ銀行ウェブサイトのRuby Interface
2
2
 
3
- Description goes here.
3
+ == インストール
4
+ gem install mizuho_bank
4
5
 
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but
13
- bump version in a commit by itself I can ignore when I pull)
14
- * Send me a pull request. Bonus points for topic branches.
6
+ == 使い方 (こんな感じで)
15
7
 
16
- == Copyright
8
+ # encoding: utf-8
9
+ Encoding.default_external = Encoding.default_internal = "UTF-8"
10
+ require 'mizuho_bank'
11
+ require 'pit'
12
+
13
+ pit = Pit.get("MizuhoBank", :require => {
14
+ "keiyaku_no" => "keiyaku_no",
15
+ "password" => "password",
16
+ "aikotoba1_question" => "aikotoba1_question",
17
+ "aikotoba2_question" => "aikotoba2_question",
18
+ "aikotoba3_question" => "aikotoba3_question",
19
+ "aikotoba1_answer" => "aikotoba1_answer",
20
+ "aikotoba2_answer" => "aikotoba2_answer",
21
+ "aikotoba3_answer" => "aikotoba3_answer",
22
+ })
23
+
24
+ aikotoba_dict = {
25
+ pit['aikotoba1_question'] => pit['aikotoba1_answer'],
26
+ pit['aikotoba2_question'] => pit['aikotoba2_answer'],
27
+ pit['aikotoba3_question'] => pit['aikotoba3_answer']
28
+ }
29
+
30
+ MizuhoBank.new(pit['keiyaku_no'].to_s, pit['password'].to_s, aikotoba_dict){ |bank|
31
+ p bank.info.main_account.money
32
+ }
33
+
34
+ == 既知の問題
35
+ まだ画像認証に対応してない。画像認証は秘密の質問に失敗しまくってるとやらなきゃいけなくなる
17
36
 
18
- Copyright (c) 2011 kimoto. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -3,6 +3,33 @@ require 'mechanize'
3
3
  require 'kconv'
4
4
  require 'logger'
5
5
  require 'retry-handler'
6
+ require 'moji'
7
+
8
+ # utility class
9
+ class String
10
+ def trim_no_number
11
+ self.gsub(/[^0-9]/, "")
12
+ end
13
+ end
14
+
15
+ class Time
16
+ def self.mizuho_time_parse(string)
17
+ p string
18
+ end
19
+ end
20
+
21
+ class Integer
22
+ def humanize
23
+ case
24
+ when self < 1000
25
+ self
26
+ when self < 1000000
27
+ (self / 1000).to_s + "千円"
28
+ when self < 1000000000
29
+ (self / 1000000).to_s + "百万"
30
+ end
31
+ end
32
+ end
6
33
 
7
34
  class MizuhoBank
8
35
  TOP_URL = "https://web.ib.mizuhobank.co.jp/servlet/mib?xtr=Emf00000"
@@ -144,25 +171,26 @@ class MizuhoBank
144
171
  info.last_logined_at = content.search("tr > td > table > tr > td > div > b")[2].text
145
172
  info.mailaddr = content.search("tr > td > table > tr > td > div > b")[4].text
146
173
 
147
- account = MizuhoAccount.new
148
- account.name = content.search("tr").search("./td/table")[2].search("table > tr")[3].search("table > tr > td > div")[1].text.toutf8.strip
149
- account.deal_type = content.search("tr").search("./td/table")[2].search("table > tr")[3].search("table > tr > td > div")[3].text.toutf8.strip
150
- account.number = content.search("tr").search("./td/table")[2].search("table > tr")[3].search("table > tr > td > div")[5].text.toutf8.strip
151
- account.money = content.search("tr").search("./td/table")[2].search("table > tr")[3].search("table > tr > td > div")[7].text.toutf8.strip
152
- account.usable_money = content.search("tr").search("./td/table")[2].search("table > tr")[3].search("table > tr > td > div")[9].text.toutf8.strip
174
+ account_tags = content.search("tr").search("./td/table")[2].search("table > tr")[3].search("table > tr > td > div")
153
175
 
154
176
  info.latest_cache_flows = []
155
- info.main_account = account
177
+ info.main_account = MizuhoAccount.new(
178
+ :name => account_tags[1].text.toutf8.strip,
179
+ :deal_type => account_tags[3].text.toutf8.strip,
180
+ :number => account_tags[5].text.toutf8.strip.trim_no_number,
181
+ :money => account_tags[7].text.toutf8.strip.trim_no_number.to_i,
182
+ :usable_money => account_tags[9].text.toutf8.strip.trim_no_number.to_i
183
+ )
156
184
 
157
185
  records = content.search("tr").search("./td/table")[2].search("./tr/td/table/tr")[6].search("table > tr > td > div")
158
186
  10.times{ |n|
159
187
  i = (n + 1) * 4
160
188
 
161
189
  cacheflow = MizuhoCacheFlow.new
162
- cacheflow.date = records[i+0].text.toutf8.strip
163
- cacheflow.money_in = records[i+1].text.toutf8.strip
164
- cacheflow.money_out = records[i+2].text.toutf8.strip
165
- cacheflow.summary = records[i+3].text.toutf8.strip
190
+ cacheflow.date = Time.parse(records[i+0].text.toutf8.strip)
191
+ cacheflow.money_in = records[i+1].text.toutf8.strip.trim_no_number.to_i
192
+ cacheflow.money_out = records[i+2].text.toutf8.strip.trim_no_number.to_i
193
+ cacheflow.summary = Moji.normalize_zen_han(records[i+3].text.toutf8.strip)
166
194
  info.latest_cache_flows << cacheflow
167
195
  }
168
196
  info
@@ -170,21 +198,26 @@ class MizuhoBank
170
198
 
171
199
  def load_cacheflow_page(data)
172
200
  content = Nokogiri(data).search("#bodycontent > div > table")[4]
201
+ account_tags = content.search("./tr/td/table/tr/td/table/tr")[1].search("./td/table/tr/td/table/tr/td/div")
173
202
 
174
- account = MizuhoAccount.new
175
- account.name = content.search("./tr/td/table/tr/td/table/tr")[1].search("./td/table/tr/td/table/tr/td/div")[1].text.toutf8.strip
176
- account.deal_type = content.search("./tr/td/table/tr/td/table/tr")[1].search("./td/table/tr/td/table/tr/td/div")[3].text.toutf8.strip
177
- account.number = content.search("./tr/td/table/tr/td/table/tr")[1].search("./td/table/tr/td/table/tr/td/div")[5].text.toutf8.strip
178
- account.money = content.search("./tr/td/table/tr/td/table/tr")[1].search("./td/table/tr/td/table/tr/td/div")[7].text.toutf8.strip
179
- account.usable_money = content.search("./tr/td/table/tr/td/table/tr")[1].search("./td/table/tr/td/table/tr/td/div")[9].text.toutf8.strip
203
+ account = MizuhoAccount.new(
204
+ :name => account_tags[1].text.toutf8.strip,
205
+ :deal_type => account_tags[3].text.toutf8.strip,
206
+ :number => account_tags[5].text.toutf8.strip.trim_no_number.to_i,
207
+ :money => account_tags[7].text.toutf8.strip.trim_no_number.to_i,
208
+ :usable_money => account_tags[9].text.toutf8.strip.trim_no_number.to_i
209
+ )
180
210
 
181
211
  account.cache_flows = []
182
212
  flows = content.search("./tr/td/table/tr/td/table/tr")[4].search("./td/table/tr/td/table/tr/td/div").map(&:text).map(&:toutf8).map(&:strip)
183
213
  (flows.size / 4 - 1).times{ |n|
184
214
  i = (n + 1) * 4
185
- cf = MizuhoCacheFlow.new
186
- (cf.date, cf.money_in, cf.money_out, cf.summary) = [flows[i], flows[i+1], flows[i+2], flows[i+3]]
187
- account.cache_flows << cf
215
+ account.cache_flows << MizuhoCacheFlow.new(
216
+ :date => Time.parse(flows[i]),
217
+ :money_out => flows[i+1].trim_no_number.to_i,
218
+ :money_in => flows[i+2].trim_no_number.to_i,
219
+ :summary => Moji.normalize_zen_han(flows[i+3])
220
+ )
188
221
  }
189
222
 
190
223
  account
@@ -214,15 +247,31 @@ class MizuhoBank
214
247
  attr_accessor :informations # reserved
215
248
  attr_accessor :main_account
216
249
  attr_accessor :latest_cache_flows
250
+
251
+ def to_s
252
+ "#<MizuhoDirectInfo #{username} #{mailaddr} #{main_account}>"
253
+ end
217
254
  end
218
255
 
219
256
  class MizuhoCacheFlow
220
257
  attr_accessor :date
221
- attr_accessor :value
222
258
  attr_accessor :summary
223
-
224
259
  attr_accessor :money_in
225
260
  attr_accessor :money_out
261
+
262
+ def initialize(options={})
263
+ options.each{ |key, value|
264
+ instance_variable_set("@#{key}", value)
265
+ }
266
+ end
267
+
268
+ def value
269
+ @money_in == 0 ? -@money_out : @money_in
270
+ end
271
+
272
+ def to_s
273
+ "#<MizuhoCacheFlow: #{@date.strftime("%Y/%m/%d")} #{@summary} #{self.value}>"
274
+ end
226
275
  end
227
276
 
228
277
  class MizuhoAccount
@@ -232,6 +281,16 @@ class MizuhoBank
232
281
  attr_accessor :money # 残高
233
282
  attr_accessor :usable_money # お引き出し可能残高
234
283
  attr_accessor :cache_flows # C/F明細
284
+
285
+ def initialize(options={})
286
+ options.each{ |key, value|
287
+ instance_variable_set("@#{key}", value)
288
+ }
289
+ end
290
+
291
+ def to_s
292
+ "#<MizuhoAccount #{@name}:#{@deal_type}:#{@number} $#{@money}(#{@usable_money})>"
293
+ end
235
294
  end
236
295
  end
237
296
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - kimoto
@@ -42,7 +42,6 @@ extra_rdoc_files:
42
42
  files:
43
43
  - VERSION
44
44
  - lib/mizuho_bank.rb
45
- - readme.txt
46
45
  - LICENSE
47
46
  - README.rdoc
48
47
  - test/test_helper.rb
data/readme.txt DELETED
@@ -1,19 +0,0 @@
1
- みずほ銀行ウェブサイトから口座残高を取得するスクリプト
2
-
3
- 2009年頃に正しく動作していることを確認しているのですが、現在は不明
4
- たぶんUI変わってるだろうし無理
5
-
6
- 暇を見つけて今後修正していく予定なので一応githubにアップ
7
-
8
- __
9
- ちなみに当時の使い方は
10
- 1. Firefoxでみずほ銀行ウェブサイトにログイン
11
- 2. ./bin/cookie.plでfirefoxのsqlite3データベースからcookie情報を取得
12
- 3. そのcookie情報を元に、mizuho.rbを実行って感じです
13
- -------------------
14
- MizuhoBank.start(pit['username'], pit['password'], pit['aikotoba1'], pit['aikotoba2']){ |bank|
15
- p bank.money
16
- }
17
- -------------------
18
- とすると標準出力に、口座残高が出力される
19
-