태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.
BLOG main image
분류 전체보기 (111)
Pragmatic tools (14)
Agile Game Project (24)
mac (4)
Web 2.0 (2)
Resource (18)
... (5)
Stared [미공개] (0)
Dev (22)
드리밍 인 코드
소프트웨어에 날개를 달자.
Redmine pdf export 시 한글 깨..
Noblesse Oblige
[Thank You for the Music] by A..
바람나무, 생각가는대로
불확실성과 화해하는 프로젝트..
The note of Legendre
iadle_dev의 생각
iadle_dev's me2DAY
71,084 Visitors up to today!
Today 1 hit, Yesterday 12 hit
daisy rss
tistory 티스토리 가입하기!
2007/05/06 23:38
제목은 거창한데 사실은 별건 아닙니다.

블로그 구독을 열심히하다보니 어느덧 500여개가 넘는 블로그를 보고 있습니다. 시간으로 따지면 하루 한시간 이상 꾸준히 투자하고 있는 셈입니다.
좀 더 생산적으로 이 시간을  활용하고자 꼼꼼히 중요한 글 체크를 해서 다시 보고 있는데 얼마전부터 1,000개 제한에 걸려 새로운 중요한 글 체크를 위해 예전 중요한 글을 지워야하는 아픔을...

시스템 부하때문에 1,000개 이상은 힘들다는 답변을 듣고, 매일매일 등록한 글을 내 블로그에 넣을 수 있으면 좋겠다는 생각을 하고 실천에 옮겼습니다.

난관 1. 공부 중인 ruby로 만들려고 했는데, 막막...
           구글신과 프로그래밍 루비 에 의지해가며 하나씩 익혀가고 있습니다.

난관 2. HanRSS  중요한 글 가져오기 API 처리 - http://www.hanrss.com/api/get_starred_items.qst
           - Http basic authentication
           - RSS Parsing
           - 잦은 테스트를 위해 파일로 저장하기

require 'rss/2.0'
require 'open-uri'

open('http://www.hanrss.com/api/get_starred_items.qst',
        :http_basic_authentication=>["twiny@naver.com", "여기에 비밀번호"]
) do |http|
    response = http.read
    result = RSS::Parser.parse(response, false)
    puts "Channel : " + result.channel.title

    result.items.each_with_index do |item, i|
       puts item.title
       puts item.description 
    end
end

* http basic authenticatoin 뿐만 아니라 rss파싱까지 모두 ruby 표준라이브러리가 있어서 해결!

난관 3. 티스토리에 등록하기 (MetaWebLogAPI를 이용)
          - MetaWebLogAPI 스펙 분석
          - MetaWebLogAPI 함수
         
require 'xmlrpc/client'

client = MetaWebLogAPI::Client.new('twiny.tistory.com','/api','BlogID','twiny@naver.com','패스워드')
...
#아래 코드는 위 코드의 result.items.each_with_index do |item,i| 블럭 안에 적절히 삽입

blogpost = {
         'title' => "#{item.title}" ,
          'description' => "<a href='#{item.link}'>원문 링크 : #{item.author}</a><br /><br />#{item.description}",
          'link' => item.link,
          'category' => 'Shared RSS' ,
          'pubDate' => item.pubDate
 }

 client.newPost(blogpost,false)

* 역시나 루비 표준라이브러리 안에 xmlrpc 가 있습니다.
* MetaWebLogAPI는 http://www.agileprogrammer.com/dotnetguy/articles/BlogImporterInRuby.aspx 에서 가져왔어용 :-)

require 'xmlrpc/client'

module MetaWebLogAPI
  class Client
    def initialize(server, urlPath, blogid, username, password)
      @client = XMLRPC::Client.new(server, urlPath)
      @blogid = blogid
      @username = username
      @password = password
    end
  
    def newPost(content, publish)
      @client.call('metaWeblog.newPost', @blogid, @username,
          @password, content, publish)
    end

    def getPost(postid)
      @client.call('metaWeblog.getPost', postid, @username,
          @password)
    end

    def editPost(postid, content, publish)
      @client.call('metaWeblog.editPost', postid, @username,
          @password, content, publish)
    end
  end
end

  - metaWeblog의 한계인지는 모르지만,  category, author, link, pubDate 모두 무시됩니다.


난관 4. me2day처럼 매일매일 내가 중요한 글로 체크한 글들을 날짜단위로 포스팅 하기
         - HanRSS에서는 pubDate에 원문날짜가 나오며 제가 중요한 글로 체크한 날짜 정보는 없습니다.
           다행히 중요한 글 체크한 날짜가 최근글로 뿌려지고 있으니까 loop을 돌때 반대로 돌아야 최글글이 위에 나타 납니다.

    result.items.each_with_index do |item, i|
       puts item.title
       puts item.description 
    end

    대신에

    result.items.reverse.each_with_index do |item,i|
       puts item.title
       puts item.description 
    end

난관 5. 제 블로그로 포스팅이 끝나면 HanRSS 중요한 글을 비워주기
          - http://www.hanrss.com/api/get_starred_items.qst?empty=1
          - 비워주면 끝인데? 테스트하기 두려움(?)

난관 6. 위의 과정을 통해 내 블로그에 엄청난 글들이 쌓이는데 이 과정에 대한 트랜잭션 개념을 도입하기
          -  client.newPost(blogpost,false) 함수의 리턴값으로 postid가 날라온다.
          - 그렇지만 postid를 이용해 티스토리 블로그에서 글 지우기가 안되는듯

난관 7. 한꺼번에 많은 글이 포스팅되면 막혀버리는 문제
          - HanRSS 중요한 글 보기 기준 중 25개 가 있으니 한번 호출에 100개씩만 이동 시키기
          - 25개 이동이 끝나면 HanRSS에서 중요한 글 4페이지를 비워주자 (수동?)
       

현재까지 진행 상황은 여기까지이며, 이 삽질을 하느라 제 블로그에 엄청한 글들이 쌓였습니다.
문제는 그 사이 메타블로그에서 긁어가는 바람에 -.- 혹시 엄청난 펌 블로그로 오해하시는 분들이 계실까봐 걱정이네요.

암튼 그래서 만들어진 소스는...

require 'rss/2.0'
require 'open-uri'
require 'xmlrpc/client'
require 'xmlrpc/client'
module MetaWebLogAPI
  class Client
    def initialize(server, urlPath, blogid, username, password)
      @client = XMLRPC::Client.new(server, urlPath)
      @blogid = blogid
      @username = username
      @password = password
    end
  
    def newPost(content, publish)
      @client.call('metaWeblog.newPost', @blogid, @username,
          @password, content, publish)
    end
    def getPost(postid)
      @client.call('metaWeblog.getPost', postid, @username,
          @password)
    end
    def editPost(postid, content, publish)
      @client.call('metaWeblog.editPost', postid, @username,
          @password, content, publish)
    end
  end
end
client = MetaWebLogAPI::Client.new('twiny.tistory.com','/api','BlogID','티스토리이메일','티스토리 비밀번호')
 
open('http://www.hanrss.com/api/get_starred_items.qst?results=100',:http_basic_authentication=>["한RSS이메일", "한RSS비밀번호"]) do |http|
    response = http.read
    result = RSS::Parser.parse(response, false)
    result.items.each_with_index do |item,i|
    category = ["Shared RSS"]
  blogpost = {
         'title' => "#{item.title}" ,
    'description' => "Source : <a href='#{item.link}' >#{item.link}</a><br/><br/>#{item.description}" ,
          'link' => item.link,
          'categories' => category ,
          'pubDate' => item.pubDate
  }
  client.newPost(blogpost,false)
 
    end
 
end

이올린에 북마크하기(0) 이올린에 추천하기(0)
Trackback Address :: http://twiny.tistory.com/trackback/637 관련글 쓰기
BlogIcon 성렬 | 2007/05/07 11:59 | PERMALINK | EDIT/DEL | REPLY
헐, 멋지십니다~ 혹시 API 설명페이지에 참고예제로 소개해도 될까요?
BlogIcon twiny | 2007/05/07 13:58 | PERMALINK | EDIT/DEL | REPLY
엇! 어떻게 아시고 여기까지^^; 보시다싶이 아직 삽질 중이라... 요 페이지로 링크를 걸어주시거나 하면 틈나는데로 업데이트 할께요.
BlogIcon 성렬 | 2007/05/07 16:04 | PERMALINK | EDIT/DEL
API 도움말 페이지(http://www.hanrss.com/help/api/)에 참고사례로 추가하였습니다. 감사합니다. ^^;
Name
Password
Homepage
Secret