Created
June 14, 2010 11:09
-
-
Save anonymous/437555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'rubygems' | |
require 'sequel' | |
require 'yahoo_blog' | |
## DB接続 + テーブル作成 ## | |
# enocoding => utf8? | |
# 日本語utf8にしなきゃいけないって記事があったのですが、自分の環境だと問題無し。 | |
options = {} | |
# user pass mydbは環境に応じて変更。。 | |
DB = Sequel.connect('mysql://user:pass@localhost/mydb', options) | |
# テーブルがない場合テーブルを作成(for yahoo blog data) | |
# BlogIdっているのかな。。 | |
DB.create_table? :yahoo_blog do | |
primary_key :id | |
String :Query | |
String :BlogId | |
String :RssUrl | |
String :Title | |
Text :Description | |
String :Url | |
String :Creator | |
String :MobileLink | |
String :SiteTitle | |
String :SiteUrl | |
DateTime :DateTime | |
end | |
## yahoo blogデータの取得 | |
query = "涼宮春日的憂鬱" | |
yobj = Yahoo_blog_search.new(query) | |
blog_data = yobj.get_all_processing_data | |
## BlogデータのDBへの挿入 | |
yblog = DB[:yahoo_blog] | |
## テーブルにyahoo blogデータを導入する | |
blog_data.each do |i| | |
yblog.insert(:BlogId => i["Id"], :Query => query, :RssUrl => i["RssUrl"],:Title => i["Title"], :Description => i["Description"] , | |
:Url => i["Url"], :Creator => i["Creator"],:MobileLink => i["mobileLink"], :SiteTitle => i["SiteTitle"] , | |
:SiteUrl => i["SiteUrl"], :DateTime => i["DateTime"] ) | |
end | |
## 導入したデータの出力 | |
puts "Blog count: #{yblog.count}" | |
yblog.each do |i| | |
puts " Query: #{i[:Query]} Title: #{i[:Title]} DateTime #{i[:DateTime]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment