Skip to content

Instantly share code, notes, and snippets.

@Constellation
Created December 23, 2008 10:12
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 Constellation/39300 to your computer and use it in GitHub Desktop.
Save Constellation/39300 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -Ku
require 'rubygems'
require 'json'
require 'mechanize'
agent = WWW::Mechanize.new
#sample iview
url = "http://209.85.173.132/search?hl=ja&q=cache%3Awedata.net%2Fdatabases%2Fiview%2Fitems"
page = agent.get(url);
resource_url = 'http://wedata.net' + page.root.search('#content div ul.links li a')[0]['href']
ary = page.root.search('li.hentry').to_ary.map {|entry|
info = {
"name" => entry.search('a.entry-title')[0].text,
"update_at" => entry.search('span.updated')[0].text,
"created_by" => entry.search('div.vcard a')[0].text,
"resource_url" => 'http://wedata.net' + entry.search('a.entry-title')[0]["href"],
"database_resource_url" => resource_url,
"data" => "",
"created_at" => entry.search('span.published')[0].text
}
data = Hash.new
entry.search('tr').to_ary.each { |tr|
data[tr.children[0].text] = tr.children[1].text
}
info["data"] = data
info
}
File.open('iview.json', 'w'){|file|
file.write(JSON.pretty_generate(ary, nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment