Skip to content

Instantly share code, notes, and snippets.

@itochan
Created July 9, 2011 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itochan/1073618 to your computer and use it in GitHub Desktop.
Save itochan/1073618 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
time = Time.now
require "nokogiri"
require "open-uri"
require "active_record"
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "ito315.com",
:username => "root",
:password => "http://bit.ly/kudasai",
:database => "mousho"
)
class Amedas < ActiveRecord::Base
end
class AmedasList < ActiveRecord::Base
end
AmedasList.find(:all, :select => "id").each do |row|
begin
id = row.id
html = Nokogiri::HTML(open("http://tenki.jp/amedas/detail-#{id}.html"))
temp = html.xpath("//table[@class='amedasuDailyTable']//tr[2]/td[2]").text
amedas = Amedas.find(id)
# amedas = Amedas.new
amedas.id = id
amedas.temp = temp
amedas.save
puts "id:#{id} temp:#{temp} #{Time.now - time}"
rescue
puts "id:#{id} skipped"
nil
end
sleep 0.1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment