Skip to content

Instantly share code, notes, and snippets.

@akameco
Created August 3, 2013 10:18
Show Gist options
  • Save akameco/6145993 to your computer and use it in GitHub Desktop.
Save akameco/6145993 to your computer and use it in GitHub Desktop.
# coding: utf-8
require "rubygems"
require "nokogiri"
require "open-uri"
require "kconv"
require "time"
def tenki
time = Time.new
doc = Nokogiri::HTML(open("http://tenki.jp/forecast/point-702.html"))
serect = '#container.yui-t6 div#bd.yui-g div#fullWidthTop div.contentsBox table#leisurePinpointWeather'
hour = Array.new
weather = Array.new
temperature = Array.new
day = Array.new
doc.search(serect).each do |m|
day = m.search(".head td").text.gsub(/\r\n/,"").chomp.split
m.search(".temperature").text.each_line("") {|line| temperature.push line.chomp.chomp }
m.search(".hour").text.each_line("") {|line| hour.push line.chomp.chomp }
m.search(".weather").text.each_line("") {|line| weather.push line.chomp.chomp }
end
weather.delete_at(0)
temperature.delete_at(0)
i = time.hour.to_i/3
weather = weather.slice(i,8)
temperature = temperature.slice(i,8)
hour = hour.slice(i,8)
str = "#{day[0]}#{day[1].gsub(/\[.+\]/,"")}の足立区のお天気予報なの♡\n"
weather.zip(hour,temperature) do |a|
str << "#{day[2]}#{day[3].gsub(/\[.+\]/,"")}\n" if a[1].to_i == 0
str << "#{a[1].rjust(1)}時:#{a[0]}:#{a[2]}度\n"
end
return str
end
Plugin.create(:adachitemki) do
command(
:tenki,
name: 'お天気ですん',
condition: -> _ { true },
visible: true,
role: :timeline
) do
str = tenki
Service.primary.post(:message => str)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment