Changeset 12692 for lang/vim

Show
Ignore:
Timestamp:
05/29/08 17:31:02 (6 months ago)
Author:
ujihisa
Message:

lang/vim/misc/mixi.vim: patch from Sixeight <add image attachment function and fix get diary info function>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/vim/misc/mixi.vim

    r12348 r12692  
    1919  end 
    2020 
    21   def post(title, body) 
     21  def post(title, body, images) 
    2222    page = @agent.get 'http://mixi.jp/home.pl' 
    2323    form = page.forms[0] 
     
    3131    form.diary_title = title 
    3232    form.diary_body = self.class.magic_body(body) 
     33    images[0, 3].each_with_index do |img, i| 
     34      eval "form.file_uploads[#{i}].file_name = '#{img}'" 
     35    end 
    3336    page = @agent.submit form 
    3437    page = @agent.submit page.forms[0] 
     
    3740  def get_latest 
    3841    page = @agent.get 'http://mixi.jp/list_diary.pl' 
    39     ["http://mixi.jp/" << page.links[35].uri.to_s.toutf8, 
    40      page.links[35].text.toutf8] 
     42    ["http://mixi.jp/" << page.links[37].uri.to_s.toutf8, 
     43    page.links[37].text.toutf8] 
    4144  end 
    4245 
     
    5154  endline = VIM.evaluate %[line("$")] 
    5255  title   = VIM.evaluate %[getline(1)] 
    53   body    = VIM.evaluate %[join(getline(2, #{endline}), "\n")] 
     56  body = VIM.evaluate(%[join(getline(2, #{endline}), "\n")]).split "\n" 
     57 
     58  images = body.reverse.inject([]) {|r, l| r.unshift l[4..-1] if l =~ /^img:/; r } 
     59  body = body[0..-(images.length + 1)].join "\n" 
    5460 
    5561  m = Mixi.new 'YOUR_EMAIL', 'YOUR_PASSWORD' 
    5662  # if you are mixi premium member: 
    5763  # m = Mixi.new 'YOUR_EMAIL', 'YOUR_PASSWORD', true 
    58   m.post title.toeuc, body.toeuc 
     64  m.post title.toeuc, body.toeuc, images 
    5965  m.get_latest.each do |line| 
    6066    VIM.evaluate %[append(#{endline}, \"#{line.chomp}\")]