티스트로 자동글쓰기 / 예시 화면

2021. 12. 26. 14:19코딩

반응형

 

아래 코드로 예시를 보여 드립니다.

 

아래 코드를 활용하여 여러분 것에 해당하는 토큰과 블로그 네임을 입력하고 파이썬 런을 돌리면 자동으로! 짠!

#터미널 설치 : pip install beautifulsoup4 
#터미널  설치 : pip install requests

import requests
from bs4 import BeautifulSoup
import datetime

access_token= '여러분 것 입력' #여러분 것 입력
blogName = 'coupangstore'  #여러분 것 입력
today = datetime.datetime.today().strftime('%Y-%m-%d')
title = '[주식]' + ' ' + today + ' ' + '오늘의 날씨'  #변경할 것 (필수)
tistory_url = 'https://www.tistory.com/apis/post/write?'

parameters = {
    'access_token':access_token,
    'blogName':blogName,
    'title' : title,
    'content' : '테스트 내용',   #변경할 것 (필수)
    'visibility' : '3', #(0:비공개-기본값, 1: 보호글, 3:발행)
    'category' : 'Living',  #(0: 기본값), 카테고리에 있는 글을 아무거나 클릭해보시면 주소 뒷부분에 category='' 라고 나옴
    'published' : '', #timestamp 이며 미래의 시간을 넣을 경우 예약 (기본값: 현재시간)
    'tag' : '태그1, 태그2, 태그3',
    'aceeptComment' : '1' #(0: 댓글 제외, 1: 댓글 허용-기본값)
    }

response = requests.post(tistory_url, params=parameters) #post는 글쓰기, #get은 보기
soup = BeautifulSoup(response.text)
print(soup.prettify())

 

반응형