Coder Social home page Coder Social logo

pytistory's Introduction

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": "[email protected]",
  "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.

pytistory's People

Contributors

jeongukjae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jake821

pytistory's Issues

์ •๋ง ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ด์Šˆ๋กœ ๊ธ€์„ ์ž‘์„ฑํ•˜๋Š”๊ฒŒ ๋งž๋Š”์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ..
์›ํ•˜๋˜ ๊ธฐ๋Šฅ์ด ๋ชจ๋‘ ๊ตฌํ˜„๋˜์–ด์žˆ์–ด์„œ, ์ƒ๊ฐํ–‡๋˜ ๊ธฐ๋Šฅ๋“ค ์‰ฝ๊ฒŒ ๊ตฌํ˜„ํ• ์ˆ˜์žˆ๊ฒ ๋„ค์š”.

์ •๋ง๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค^^

์ถ”ํ›„์— (๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด? ใ… ใ… ) ์ €๋„ ์‚ฌ์šฉํ•˜๋‹ค๊ฐ€ ๊ณต๋ถ€ํ•ด์„œ ๊ฐ™์ด ๊ธฐ์—ฌํ• ์ˆ˜์žˆ๋Š”๊ฒƒ๋“ค์ด ์žˆ์„์ˆ˜์žˆ๋„๋ก ํ• ๊ป˜์š”.

list ์—์„œ page ์ง€์ •

tistory ๋ฅผ ์ „์ฒด ๋ฐฑ์—…์„ ์ง„ํ–‰ํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค.

img_187

ํ˜„์žฌ list ํ•จ์ˆ˜์˜๊ฒฝ์šฐ ์ตœ์‹  page ๋งŒ ์ง€์›ํ•˜๋Š”๊ฒƒ ๊ฐ™์€๋ฐ์š”. ํ˜น์‹œ ํƒ€๊ฒŸ ํŽ˜์ด์ง€๋ฅผ ์ง€์ •ํ• ์ˆ˜์žˆ๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
๊ฒ€ํ† ๋ถ€ํƒ๋“œ๋ฆด๊ป˜์š”.

    def list(self, blog_name=None, target_url=None, page_num=None):
        """post/list API ๊ตฌํ˜„์ž…๋‹ˆ๋‹ค.

        ์ตœ๊ทผ ๊ฒŒ์‹œ๋ฌผ ๋ชฉ๋ก์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋Š” API์ž…๋‹ˆ๋‹ค. ํ•ด๋‹น API์— ๊ด€ํ•œ ์ •๋ณด๋Š”
        `๋งํฌ <http://www.tistory.com/guide/api/post.php#post-list>`_ ๋ฅผ ํ†ตํ•ด
        ์‚ดํŽด๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

        :param blog_name: ๋ธ”๋กœ๊ทธ ๋ช…์ž…๋‹ˆ๋‹ค., defaults to None
        :type blog_name: str, optional
        :param target_url: ๋ธ”๋กœ๊ทธ์˜ url์ž…๋‹ˆ๋‹ค. deprecated๋œ ์˜ต์…˜์ž…๋‹ˆ๋‹ค., defaults to None
        :type target_url: str, optional
        :param page_num: ๋ฆฌ์ŠคํŠธ๋ฅผ ์–ป์–ด์˜ฌ ํƒ€๊ฒŸ ํŽ˜์ด์ง€์ž…๋‹ˆ๋‹ค.
        :type page_num: int, optional
        :raise NoSpecifiedBlog: ๋ธ”๋กœ๊ทธ ์ •๋ณด๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์—†์„ ๋•Œ ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.
        :raise TypeError: ์ธ์ž์˜ ํƒ€์ž…์ด ์ž˜๋ชป๋˜์—ˆ์„ ๋•Œ ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.
        :return:
            `์ตœ๊ทผ ๊ฒŒ์‹œ๊ธ€ ๋ชฉ๋ก API <http://www.tistory.com/guide/api/post.php#post-list>`_ ๋งํฌ์—์„œ
            ์–ด๋–ค ๋ฐ์ดํ„ฐ๊ฐ€ ๋„˜์–ด์˜ค๋Š” ์ง€ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
        :rtype: dict
        """
        url = self._get_url(self.kind, 'list')
        params = self._get_default_params()
        self._set_blog_name(params, blog_name, target_url)

        if isinstance(page_num, int) and visibility >= 1:
            params['page'] = page_num
        else:
            raise TypeError('A page_num must be number.')

        response = self._perform('GET', url, params=params)

        return response

list ํ•จ์ˆ˜ page ์ง€์ •

tistory ๋ฅผ ์ „์ฒด ๋ฐฑ์—…์„ ์ง„ํ–‰ํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค.

img_187

ํ˜„์žฌ list ํ•จ์ˆ˜์˜๊ฒฝ์šฐ ์ตœ์‹  page ๋งŒ ์ง€์›ํ•˜๋Š”๊ฒƒ ๊ฐ™์€๋ฐ์š”. ํ˜น์‹œ ํƒ€๊ฒŸ ํŽ˜์ด์ง€๋ฅผ ์ง€์ •ํ• ์ˆ˜์žˆ๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
๊ฒ€ํ† ๋ถ€ํƒ๋“œ๋ฆด๊ป˜์š”.

    def list(self, blog_name=None, target_url=None, page_num=None):
        """post/list API ๊ตฌํ˜„์ž…๋‹ˆ๋‹ค.

        ์ตœ๊ทผ ๊ฒŒ์‹œ๋ฌผ ๋ชฉ๋ก์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋Š” API์ž…๋‹ˆ๋‹ค. ํ•ด๋‹น API์— ๊ด€ํ•œ ์ •๋ณด๋Š”
        `๋งํฌ <http://www.tistory.com/guide/api/post.php#post-list>`_ ๋ฅผ ํ†ตํ•ด
        ์‚ดํŽด๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

        :param blog_name: ๋ธ”๋กœ๊ทธ ๋ช…์ž…๋‹ˆ๋‹ค., defaults to None
        :type blog_name: str, optional
        :param target_url: ๋ธ”๋กœ๊ทธ์˜ url์ž…๋‹ˆ๋‹ค. deprecated๋œ ์˜ต์…˜์ž…๋‹ˆ๋‹ค., defaults to None
        :type target_url: str, optional
        :param page_num: ๋ฆฌ์ŠคํŠธ๋ฅผ ์–ป์–ด์˜ฌ ํƒ€๊ฒŸ ํŽ˜์ด์ง€์ž…๋‹ˆ๋‹ค.
        :type page_num: int, optional
        :raise NoSpecifiedBlog: ๋ธ”๋กœ๊ทธ ์ •๋ณด๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์—†์„ ๋•Œ ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.
        :raise TypeError: ์ธ์ž์˜ ํƒ€์ž…์ด ์ž˜๋ชป๋˜์—ˆ์„ ๋•Œ ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.
        :return:
            `์ตœ๊ทผ ๊ฒŒ์‹œ๊ธ€ ๋ชฉ๋ก API <http://www.tistory.com/guide/api/post.php#post-list>`_ ๋งํฌ์—์„œ
            ์–ด๋–ค ๋ฐ์ดํ„ฐ๊ฐ€ ๋„˜์–ด์˜ค๋Š” ์ง€ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
        :rtype: dict
        """
        url = self._get_url(self.kind, 'list')
        params = self._get_default_params()
        self._set_blog_name(params, blog_name, target_url)

        if isinstance(page_num, int) and visibility >= 1:
            params['page'] = page_num
        else:
            raise TypeError('A page_num must be number.')

        response = self._perform('GET', url, params=params)

        return response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.