人気ブログランキング | 話題のタグを見る
以前、net/httpでドハマリしたことがある。
ネット検索したけど、俺のエラーの質問と同じ事だけ載ってた。
役しねえ。
さんざん、コネくりまわしたあげくに、ruby/ioに手を出した。
純粋ルビーじゃないので抵抗はあったが、やってみるものだ。
と言うことでLinux以外の人ごめんなさい。
io = IO.popen("wget -q -O - %s 2" % url)
この一行に辿り着きました。
内緒で使ってたけど、ブログを書き始めたと言うことで載せちゃいます。
普段はパイプでnkfを通して使ってます。
試したい人は自力で。と言ってもそんなに難しくないけど。
printf,format使ってる人
"wget -q -O - %s 2" % url
この書き方もステキ
今日はyahoo天気から日本列島の上空写真をダウンロードして表示する奴。

#!/usr/bin/env ruby

require 'rubygems'
require 'sdl'

class Cell
def initialize(surface)
@home = surface
self.file_download
self.load_image("weather.jpg")
@x = (@home.w - @w) / 2
@y = (@home.h - @h) / 2
end
def file_download
url = "http://weather.yahoo.co.jp/weather/"
html = ""
io = IO.popen("wget -q -O - %s 2" % url)
while line = io.gets
html << line
end
io.close
if /satellite.html(.*?)width/ =~ html
if /(http.*?)"/ =~ $1
url = $1
end
end
io = IO.popen("wget -q -O weather.jpg %s" % url)
io.close
end
def load_image(image_file)
@surface = SDL::Surface.load(image_file).display_format
@w,@h = @surface.w,@surface.h
end
def blit
SDL::Surface.blit(@surface,0,0,@w,@h,@home,@x,@y)
end
end

class Phase
def initialize(screen)
@screen = screen
@screen.fill_rect(0,0,@screen.w,@screen.h,[80,80,80])
@cell = Cell.new(@screen)
@cell.blit
@screen.update_rect(0,0,0,0)
end
def run
loop do
while event=SDL::Event.poll
case event
when SDL::Event::Quit
exit
when SDL::Event::KeyDown
exit if event.sym == SDL::Key::ESCAPE
end
end
end
end
end

SDL.init( SDL::INIT_VIDEO )
SDL::Mouse.hide
SDL::WM.set_caption("Weather","")
screen = SDL::setVideoMode(300,250,16,SDL::SWSURFACE)
Phase.new(screen).run
# by gaziya | 2010-08-27 20:46