/pytistory

๐Ÿ“– Tistory Blog API Client written in Python.

Primary LanguagePythonMIT LicenseMIT

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.