Skip to content

Instantly share code, notes, and snippets.

@koduki
Created October 9, 2010 16:11
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 koduki/618333 to your computer and use it in GitHub Desktop.
Save koduki/618333 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'mechanize'
require 'uri'
class DokushoMeter
def initialize
@agent = WWW::Mechanize.new
@agent.user_agent_alias = 'Windows IE 7'
end
def login id, password
@agent = WWW::Mechanize.new
@agent.user_agent_alias = 'Windows IE 7'
page = @agent.get('http://book.akahoshitakuya.com/login')
page.forms[1].fields_with(:name => 'mail').first.value = id
page.forms[1].fields_with(:name => 'password').first.value = password
page.forms[1].click_button
end
def import books
books.each do |book|
@agent.get("http://book.akahoshitakuya.com/add.php?asin=#{book[:isbn10]}&title=#{URI.encode book[:name]}")
sleep 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment