pytistory

티스토리 블로그 api client입니다.


Keywords
tistory, blogging, api-client, api-wrapper, python-library
License
MIT
Install
pip install pytistory==0.0.2

Documentation

PyTistory

https://circleci.com/gh/JeongUkJae/pytistory.svg?style=shield https://travis-ci.org/JeongUkJae/pytistory.svg?branch=master https://requires.io/github/JeongUkJae/pytistory/requirements.svg?branch=master Documentation Status

PyTistory는 티스토리 오픈 API 가이드 를 참고하여 Python으로 작성한 티스토리 API 클라이언트입니다. 티스토리 오픈 API 가이드 인증 방식 중 Client-side flow 방식에 따라 구현되었습니다. 자세한 사용법은 PyTistory Documentation 에서 확인하실 수 있습니다.

Installation

pytistory는 pip를 통해 설치할 수 있습니다.

$ pip install pytistory

사용법

사용자 인증

인증정보는 다음과 같은 우선순위를 통해 적용됩니다.

  • 직접 설정하는 configure함수로 넘어오는 access_token인자값
  • configure함수로 넘어오는 client_id, tistory_id, tistory_password인자값
  • configure함수로 넘어오는 file_name에서 읽어들인 인자값
  • 환경변수값
  • 기본 파일(~/.pytistory/credentials.ini)에 설정되어 있는 값

즉, 환경변수, 기본 설정 파일에 client id가 적용되어 있다 하더라도 직접 넘기는 file_name에 존재하는 설정들에 의해 덮어씌워지고, 직접 인자값으로 넘기는 client_id등의 인자값에 의해 덮어씌워집니다.

access_token이 인자로 넘어올 경우 다른 옵션은 전부 무시하고, access_token만을 설정합니다.

직접 Access Token 설정

from pytistory import PyTistory

pytistory = PyTistory()
pytistory.configure(
  access_token='some-example-access-token')

함수의 인자값을 통한 설정

from pytistory import PyTistory

pytistory = PyTistory()
pytistory.configure(
  client_id='some-example-client-id',
  tistory_id='some-example-tistory-id',
  tistory_password='some-example-tistory-password')

파일을 통한 설정

from pytistory import PyTistory

pytistory = PyTistory()
pytistory.configure(
  file_name='./some/path/to/credentials.ini')

파일 형식은 ini(Initialization)을 따릅니다.

[pytistory]
client_id=some-client-id
tistory_id=some-tistory-id
tistory_password=some-tistory-password

환경변수를 통한 설정

환경 변수로는 다음과 같이 설정할 수 있습니다.

export PYTISTORY_CLIENT_ID=some-example-client-id
export PYTISTORY_TISTORY_ID=some-example-tistory-id
export PYTISTORY_TISTORY_PASSWORD=some-example-tistory-password

API호출

https://www.tistory.com/apis/kind/action 와 같은 api를 호출할 경우 아래처럼 호출합니다.

from pytistory import PyTistory

pytistory = PyTistory()
pytistory.configure()

response = pytistory.kind.action(args...)

예시로 블로그 정보를 받아오는 코드는 아래와 같습니다.

from pytistory import PyTistory

pytistory = PyTistory()
pytistory.configure()

response = pytistory.blog.info()

결과값은 아래처럼 받을 수 있습니다.

{
  "status": "200",
  "id": "blogtest_080@hanmail.net",
  "item": [
    {
      "url": "http://oauth.tistory.com",
      "secondaryUrl": "http://",
      "nickname": "Tistory API",
      "title": "나만의 앱, Tistory OAuth API 로 만들어보세요!",
      "description": "",
      "default": "Y",
      "blogIconUrl":
        "http://i1.daumcdn.net/cfs.tistory/blog/79/795307/index.gif",
      "faviconUrl":
        "http://i1.daumcdn.net/cfs.tistory/blog/79/795307/index.ico",
      "profileThumbnailImageUrl":
        "http://cfile1.uf.tistory.com/R106x0/1851DB584DAF942950AF29",
      "profileImageUrl":
        "http://cfile1.uf.tistory.com/R106x0/1851DB584DAF942950AF29",
      "statistics": {
        "post": "3",
        "comment": "0",
        "trackback": "0",
        "guestbook": "0",
        "invitation": "0"
      }
    },
    {
      "url": "http://oauth2.tistory.com",
      "secondaryUrl": "http://",
      "nickname": "Tistory API",
      "title": "나만의 비밀 홈",
      "description": "",
      "default": "N",
      "blogIconUrl":
        "http://i1.daumcdn.net/cfs.tistory/blog/79/795308/index.gif",
      "faviconUrl":
        "http://i1.daumcdn.net/cfs.tistory/blog/79/795308/index.ico",
      "profileThumbnailImageUrl": "",
      "profileImageUrl": "",
      "blogId": "795308",
      "statistics": {
        "post": "0",
        "comment": "0",
        "trackback": "0",
        "guestbook": "0",
        "invitation": "0"
      }
    }
  ]
}

기여

이 프로젝트는 부족한 점이 많습니다. Contribution은 언제나 환영입니다. 혹시 오류, 버그 혹은 업데이트가 필요한 점이 있으시다면 PR 또는 Issue 를 통해 언제든지 알려주세요. 👏

Copyright & License

Copyright (c) 2018 JeongUkJae. MIT License.