1

私は冬休み中に自分自身に小さなプロジェクトを与えており、デスクトップで使用できる小さな geektool スクリプトを書こうとしています。これは ruby​​ 用に書いたもので、ターミナルでは動作しますが、textmate で実行すると host is down エラーが発生し、geektool に配置すると実行されません。

 #!/usr/bin/ruby

require 'open-uri'
require 'nokogiri'

def fetch_xml()
  open("http://weather.yahooapis.com/forecastrss?w=2424766&u=f")
end


def parse_xml()
    source = Nokogiri::XML(fetch_xml)
    location = source.xpath("//yweather:location")
    condition = source.xpath("//item//yweather:condition")
    forecast = source.xpath("//item//yweather:forecast")
    [location[0]['city'], location[0]['region'], condition[0]['temp'].to_i, condition[0]['text'], forecast[0]['high'], forecast[0]['low']]
end


def display_weather()
  result = parse_xml()
  print "#{result}\n"
end


display_weather

端末で実行され、正しい出力が得られます: ["Houston", "TX", 64, "Cloudy", "69", "63"]

しかし、前述したように、textmate 内では実行されず、geektool には何も表示されません。助けてくれてありがとう。

4

0 に答える 0