티스토리 툴바


import xmlrpclib

def test_MetaWebBlogAPI( ):

    user = 'user@mail.com'
    passwd = 'password'
    server = xmlrpclib.ServerProxy('http://gotham.tistory.com/api')
    blog_id = 1212 # API KEY
    title = 'test title'
    content = 'test content, from python'

    blog_content = { 'title' : title, 'description' : content }
    categories = [{'categoryId' : 'programming', 'isPrimary' : 1}]

    post_id = server.metaWeblog.newPost(blog_id, user, passwd, blog_content,0)
    server.mt.publishPost(post_id, user, passwd)

if __name__ == "__main__" :

    test_MetaWebBlogAPI()


원 코드가 있는 포스트는 http://vizible.wordpress.com/2009/01/25/post-wordpress-entry-with-python/

그런데 wordpress랑 다르게 titstory에서는 post_id로 int형을 내 뱉지 않고 apikey-postid 로 결과를 준다.
그래서 그 부분만 바꿈.

테스트 결과 잘 되드라~~



덧.  short history

DNA에서 API문서를 봤을 때는
http://dna.daum.net/apis/tistory

Blogger 1.0 API가 처음에 나오고 쉬워이는데다가 구글에서 플젝까지 있어서
처음 시도를 하게 되었다.
http://code.google.com/apis/blogger/docs/1.0/developers_guide_python.html

그런데 python용 gdata 라이브러리를 설치하고 test를 돌려보니 실패.
기본 python path가 /usr/env 에 있는 걸 쓰는 것도 아니고
/usr/bin으로만 잡혀 있었던 것이다.

파이썬 높은 버전을 쓰기 떄문에 /usr/local/bin으로
경로가 잡혀 있는 나는 중간에  가볍게 짜증을 내주고.

그냥 어차피 XML로 포멧해서 request날려주면 되는데 내가 괜히 이거 쓰려고 하나?
라고 하면서 진행하려다가 DNA문서부터 읽어보기로 함.

다시 DNA문서를 살펴보니 Blogger1.0을 개량한 MetaWebBlog 발견

간단하게 원격 포스팅 성공.

MSDN에 있는 MetaWebBlog API
http://msdn.microsoft.com/en-us/library/bb259697.aspx



덧2. DNA

빈약하다.

쯔읍.



Posted by 페리

----------------------------------------------

#!/usr/local/bin/python
# -*- coding: utf-8 -*-

import threading
import hashlib


my_string = 'MD5 test '

g_md5_hash = hashlib.md5()

result1 = set()
result2 = set()
result3 = set()

class MD5Test1( threading.Thread ):
    def run( self ):
        for i in range(100):
            g_md5_hash.update( my_string )
            hash_val = g_md5_hash.hexdigest()
            result1.add( hash_val )

class MD5Test2( threading.Thread ):
    def run( self ):
        m = hashlib.md5()
        for i in range(100):
            m.update( my_string )
            hash_val = m.hexdigest()
            result2.add( hash_val )

class MD5Test3( threading.Thread ):
    def run( self ):
        for i in range(100):
            m = hashlib.md5()
            m.update( my_string )
            hash_val = m.hexdigest()
            result3.add( hash_val )


if __name__ == "__main__" :
    threads = []

    for i in range(10):
        th = MD5Test1()
        th.start()
        threads.append( th )

    for th in threads :
        th.join()

    print len( result1 )

    threads = []

    for i in range(10):
        th = MD5Test2()
        th.start()
        threads.append( th )

    for th in threads :
        th.join()

    print len( result2 )

threads = []

    for i in range(10):
        th = MD5Test3()
        th.start()
        threads.append( th )

    for th in threads :
        th.join()

    print len( result3 )


------------------------------------------------------------------


돌려보면 결과는

1000
100
1

여러 쓰레드에서 데이터를 모아온 다음에 md5로 키를 만들고
sorting해서 정렬하는 뭔가를 만들다가
잘 안되길래 테스트해봤는데,
내가 생각하던 것과는 다른 결과가 나왔다.

아 흙흙

혹시 마샬링 과정에 문제가 있는지
아니면 null char가 영향을 미치는지

그 외 잡다한 고민으로 시간을 보내다가
혹시나 하는 생각에 위 코드 만들어서 돌려보고 씁쓸해짐

이제 후딱 만들어야지.


Posted by 페리