[#44578] Ruby初心者が作りました — Kabu and Ruby管理人 <kabu_and_ruby@...>

http://www.geocities.jp/kabuandruby/index.html

26 messages 2008/02/06

[#44691] ”Rubyアプリケーションプログラミング”の伝言サーバの使い方 — "Yangkook Kim" <yangkookkim@...>

キムと申します。オーム社から出版されている書籍、"Rubyアプリケーションプログラミング"のP267~275に掲載されている伝言サーバー&クライアントの利用の仕方がわかりません。質問を要約すると次の2点です。1、サーバーが正常に起動されているかどうかわからない。2、書き込みクライアントで入力をサーバーに送信する方法がわからない。

8 messages 2008/02/24

[ruby-list:44675] Re: beginで捉えられないエラー??

From: Kabu and Ruby管理人 <kabu_and_ruby@...>
Date: 2008-02-22 05:55:18 UTC
List: ruby-list #44675
自己レスです。
すいません。分かったかもしれません。
もうちょっと色々やってみてわからなかったらまた質問させてください!!

Kabu and Ruby管理人
Web site: 『Rubyを使ってみよう!!』 http://www.geocities.jp/kabuandruby/
e-mail: kabu_and_ruby@ybb.ne.jp

----- Original Message ----- 
From: "Kabu and Ruby管理人" <kabu_and_ruby@ybb.ne.jp>
To: "ruby mailing list" <ruby-list@ruby-lang.org>
Sent: Friday, February 22, 2008 2:02 PM
Subject: [ruby-list:44674] beginで捉えられないエラー??


> いろいろやってみたのですが、うまく行かないので質問させてください。
> KirbyBaseというデータベースに株価データを取り込むようにしたのですが、最初のうちは順調に取り込んでいますが、以下のようなエラーが出てしまいます。
> 全体をbegin ... rescue ... endで括ったりしたのですが、やはりエラーが出てしまいます。
> ライブラリからのエラーのようですが、どういう意味でしょうか? とほほ、、。
>
>
> c:/ruby/lib/ruby/1.8/timeout.rb:54:in `rbuf_fill': execution expired 
> (Timeout::E
> rror)
>        from c:/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
>        from c:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
>        from c:/ruby/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
>        from c:/ruby/lib/ruby/1.8/net/protocol.rb:86:in `read'
>        from c:/ruby/lib/ruby/1.8/net/http.rb:2241:in `read_chunked'
>        from c:/ruby/lib/ruby/1.8/net/http.rb:2216:in `read_body_0'
>        from c:/ruby/lib/ruby/1.8/net/http.rb:2182:in `read_body'
>        from c:/ruby/lib/ruby/1.8/open-uri.rb:258:in `open_http'
>         ... 14 levels...
>        from GetAllDataKB_ver0.01.rb:59:in `step'
>        from GetAllDataKB_ver0.01.rb:59
>        from GetAllDataKB_ver0.01.rb:17:in `downto'
>        from GetAllDataKB_ver0.01.rb:17
>
> コードはこんな感じです。
>
> #! ruby -Ks
> require 'open-uri'
> require 'nkf'
> require 'jcode'
> require 'date'
> require 'kirbybase'
> require 'kconv'
> $KCODE='s' # 漢字コードをEUCに。Windowsでは 's'
>
>
> today = Date::today
> yahooformat = Regexp.new( '(\d+)年(\d+)月(\d+)日</small></td><td><small>([\d,]+)</small></td><td><small>([\d,]+)</small></td><td><small>([\d,]+)</small></td><td><small><b>([\d,]+)</b></small></td><td><small>([\d,]+)</small></td><td><small>([\d,]+)' 
>  )
>
> storedir = 'c:\ruby\kabu\tbl'
>
>
> 9350.downto(5000) do |meigara|
> begin
>
> db = KirbyBase.new
>
> puts "#{meigara}のデータ取得を開始します。"
> begin
>  Dir::chdir( storedir )
> rescue
>  puts "#{storedir}は存在しません。作成します。"
>  Dir::mkdir( storedir )
>  Dir::chdir( storedir )
> end
> begin
>  Dir::chdir( "#{meigara}" )
> rescue
>  puts "#{meigara}フォルダは存在しません。作成します。"
>  Dir::mkdir( "#{meigara}" )
>  Dir::chdir( "#{meigara}" )
> end
> begin
>  stock_tbl = db.get_table( meigara.to_s.intern )
> rescue
>  puts "#{meigara}のテーブルは存在しません。作成します。"
>  stock_tbl = db.create_table( meigara.to_s.intern , :銘柄番号 , 
> {:DataType=>:String, :Index=>1} , :年月日 , {:DataType=>:String, 
> :Index=>2} , :始値 , :Integer , :高値 , :Integer , :安値 , :Integer , :終値, :Integer , :出来高 , :Integer , :調整後終値 , :Integer)
> end
>
> if stock_tbl.total_recs == 0
>  lastdate = Date::new(1983 , 1 , 4)
>  puts "#{meigara}はデータが保存されていません。取得を試みます。"
> else
>  lastdatestr = (stock_tbl[stock_tbl.total_recs].年月日).split(/\s*-\s*/)
>  lastdate = Date::new(lastdatestr[0].to_i , lastdatestr[1].to_i , 
> lastdatestr[2].to_i)
>  if lastdate >= today
>   next
>  end
>  lastdate = lastdate + 1
> end
>
> max = today - lastdate
> strall = Array.new
>
> 0.step(max , 50) do |i|
>
> yahoourl = 
> "http://table.yahoo.co.jp/t?s=#{meigara}.t&a=#{lastdate.month}&b=#{lastdate.day}&c=#{lastdate.year}&d=#{today.month}&e=#{today.day}&f=#{today.year}&g=d&q=t&y=#{i}&z=#{meigara}.t&x=.csv"
>
>  begin
>   f = open( yahoourl )
>  rescue
>   puts 'タイムアウトです。再試行します。'
>   retry
>  end
>
>  str  = Array.new
>  temp = String.new
>  temp = f.read.tosjis
>
>  temp.each_line do |line|
>   line = line.gsub("," , "")
>   if line.scan(/#{yahooformat}/) != []
>    str.push line.scan(/#{yahooformat}/)
>   end
>  end
>
>  if str == []
>   break
>  end
>
>  strall.push str
>
>  end
>
>
>
> str2 = Array.new
>
> strall.each do |s|
>  s.each do |t|
>   t.each do |u|
>    str2.push u
>   end
>  end
> end
>
> if str2 == []
>  next
> end
>
> puts "#{meigara}のデータをテーブルに出力します。"
> str2.reverse_each do |u|
>  stock_tbl.insert( "#{meigara}" , Date::new( u[0].to_i , u[1].to_i , 
> u[2].to_i ).to_s , u[3].to_i , u[4].to_i , u[5].to_i , u[6].to_i , 
> u[7].to_i , u[8].to_i )
> end
>
> rescue
> puts 'エラーです。リトライします。'
> retry
> end
> end
>
>
> Kabu and Ruby管理人
> Web site: 『Rubyを使ってみよう!!』 http://www.geocities.jp/kabuandruby/
> e-mail: kabu_and_ruby@ybb.ne.jp
>
>
> __________ NOD32 2894 (20080221) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.eset.com
>
> 


In This Thread