end
puts "filename : #{filename}"
# load
- category = ""
- title = ""
src_text = ""
- content = ""
File.open(filename, "r") do |file|
- line = file.gets
- line = Kconv::toutf8(line)
- line.gsub!(/^<(.*)>\s+/) do |str|
- category = $1
- if get_categories.include?(category)
- puts "category : #{category}"
- else
- puts "unknown category : #{category}"
- end
- str.replace("")
- end
- title = line
- puts "title : #{title}"
src_text = file.read
src_text = Kconv::toutf8(src_text)
end
- entry = BlogEntry.new(@conf, title, category)
- if @conf.convert_to_html == true
- src_text = check_image_file(filename, src_text)
- content = Parser.new(@conf, @plugin, @service).to_html(src_text, entry)
- if @conf.html_directory != nil
- save_html_file(@conf.html_directory, File.basename(filename), content)
- end
- else
- content = src_text
- end
- entry.content = content
- if $DEBUG
- puts "category: " + entry.category
- puts "title: " +entry.title
- puts "contnt: " + entry.content
- end
-
- command = Command::new(@conf.auth_type)
+ entry = Parser.new(@conf, @plugin, @service).get_entry(src_text)
+
if @edit_uri_h[File.basename(filename)] == nil
# post
if dry_run == false
-# edit_uri = command.post(@conf.post_uri, @conf.username,
-# @conf.password,
-# entry)
edit_uri = @service.post_entry(entry.content, entry.title, entry.category)
if $DEBUG
puts "editURI : #{edit_uri}"
# edit
if dry_run == false
edit_uri = @edit_uri_h[File.basename(filename)]
- command.edit(edit_uri, @conf.username, @conf.password,
- entry)
+ @service.edit_entry(edit_uri, entry)
entry.get_entry_info(edit_uri)
end
end
uri = URI.parse(uri_str)
Net::HTTP.start(uri.host, uri.port) do |http|
res = http.post(uri.path, entry_xml,
- authenticate(@username, @password).update({'Content-Type' => 'application/atom+xml'}))
+ authenticate(@username, @password, @authtype).update({'Content-Type' => 'application/atom+xml'}))
case res.code
when "201"
edit_uri = res['Location']
@service = service
end
+ def get_entry(src_text)
+ lines = src_text.rstrip.split(/\r?\n/)
+ first_line = lines.shift
+ category = nil
+ first_line.gsub!(/^<(.*)>\s+/) do |str|
+ category = $1
+ str.replace("")
+ end
+ title = first_line
+ src_text = lines.join("\n")
+ @entry = BlogEntry.new(@conf, title, category)
+ if @conf.convert_to_html == true
+# src_text = check_image_file(filename, src_text)
+ content = to_html(src_text)
+# if @conf.html_directory != nil
+# save_html_file(@conf.html_directory, File.basename(filename), content)
+# end
+ else
+ content = src_text
+ end
+ @entry.content = content
+ return @entry
+ end
+
def escape_html(str)
str.gsub!(/&/, '&')
str.gsub!(/"/, '"')
return str
end
+# def to_html(src, entry = nil)
def to_html(src, entry = nil)
- @entry = entry
+ if entry != nil
+ @entry = entry
+ end
buf = []
lines = src.rstrip.split(/\r?\n/).map {|line| line.chomp}
require 'cgi'
require 'ldblogwriter/atompub.rb'
+require 'ldblogwriter/service.rb'
module LDBlogWriter
class LiveDoor < AbstractService
get_resource_uri(@atom_client, @config.atom_pub_uri)
end
- def post_entry(conetent, title, category = nil)
+ def post_entry(content, title, category = nil)
return @atom_client.create_entry(@entry_uri, to_xml(content, title, category))
end
xmlns:app="http://www.w3.org/2007/app"
xmlns:blogcms="http://blogcms.jp/-/atom">
EOF
- data += "<title>#{@title.chomp}</title>\n"
+ data += "<title>#{title.chomp}</title>\n"
# # <link rel="alternate" type="text/html"
# href="http://blog.livedoor.jp/staff/archives/000000.html" />
data += "<content type=\"text/html\" xml:lang=\"ja\">\n"
# data += [@content].pack("m").chomp
- data += CGI::escapeHTML(@content)
+ data += CGI::escapeHTML(content)
data += "</content>\n"
- data += "<category scheme=\"http://livedoor.blogcms.jp/atom/blog/masahino123/category\" term=\"#{@category.chomp}\"/>\n"
+ data += "<category scheme=\"http://livedoor.blogcms.jp/atom/blog/masahino123/category\" term=\"#{category.chomp}\"/>\n"
# <blogcms:source>
# <blogcms:body><![CDATA[<p>記事本文</p>]]></blogcms:body>
require 'kconv'
BooklogHomeURI = 'http://booklog.jp'
- BooklogLoginURI = 'http://booklog.jp/login.php'
- BooklogInputURI = 'http://booklog.jp/input.php'
+ BooklogLoginURI = 'http://booklog.jp/login'
+ BooklogInputURI = 'http://booklog.jp/input'
def initialize(user_id, password)
@agent = WWW::Mechanize.new
@agent.post_connect_hooks << lambda{|params| params[:response_body] = NKF.nkf('-w8m0', params[:response_body])}
# login_form = login_page.forms.with.action("./uhome.php").first
login_form = login_page.form_with(:name => 'frm')
login_form.account = user_id
- login_form.pw = password
+ login_form.password = password
result_page = login_form.submit
end
# ISBNによる登録
def input(isbn_list)
input_page = @agent.get(BooklogInputURI)
- input_form = input_page.form('frm')
- input_form['asin'] = isbn_list.join("\n")
- result_page = input_form.submit
+ input_form = input_page.form_with(:action => BooklogInputURI)
+ input_form['isbns'] = isbn_list.join("\n")
+# result_page = input_form.submit
+ result_page = input_form['buttons'].click
+ pp result_page
end
def comment(asin, comment)
end
def test_authentication
- Booklog::Agent.new(@config.options['booklog_userig'], @config.options['booklog_password'])
+ Booklog::Agent.new(@config.options['booklog_userid'], @config.options['booklog_password'])
end
+ def test_input
+ agent = Booklog::Agent.new(@config.options['booklog_userid'], @config.options['booklog_password'])
+ agent.input(['4480426280'])
+ end
end
end
# -*- coding: utf-8 -*-
-$LOAD_PATH.unshift '../lib'
+$LOAD_PATH.unshift 'lib'
+
require 'test/unit'
require 'ldblogwriter/config.rb'
class TestParser < Test::Unit::TestCase
def setup
- @conf = LDBlogWriter::Config.new('test.conf')
+ @conf = LDBlogWriter::Config.new('test/test.conf')
@parser = LDBlogWriter::Parser.new(@conf, nil)
end
def test_to_html
+ str = "テスト。\n\n空行ごとに分離されるとうれしいな。\n"
assert_equal("<p>\nテスト。\n</p>\n<p>\n空行ごとに分離されるとうれしいな。\n</p>",
- @parser.to_html("テスト。\n\n空行ごとに分離されるとうれしいな。\n"))
+ @parser.to_html(str))
end
def test_parse_img
def test_parse_a_href
entry = LDBlogWriter::BlogEntry.new(@conf, "test", "category")
@parser.to_html("[[hoge:http://blog.livedoor.jp/masahino123/archives/64994357.html]]", entry)
- assert_equal(["http://app.blog.livedoor.jp/masahino123/tb.cgi/64994357"],
+ assert_equal(["http://trackback.blogsys.jp/livedoor/masahino123/64994357"],
entry.trackback_url_array)
end
def test_parse_p
end
- def tet_a_href
+ def test_a_href
end
-
+ def test_get_entry
+ entry = @parser.get_entry("<hoge> title")
+ assert_equal("hoge", entry.category)
+ assert_equal("title", entry.title)
+
+ entry = @parser.get_entry("title2")
+ assert_equal(nil, entry.category)
+ assert_equal("title2", entry.title)
+ entry
+ end
end