Skip to content

Commit

Permalink
Add blogger
Browse files Browse the repository at this point in the history
Signed-off-by: Choonho Son <[email protected]>
  • Loading branch information
Choonho Son committed Oct 31, 2023
1 parent 138be84 commit da99a08
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
python -m pip install --upgrade pip
pip install -e .
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secret.BLOGSPOT_BASE64 }}

- name: execute python script
env:
BLOG_NAME: ${{ secrets.BLOG_NAME }}
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ authors = [
]

dependencies = [
'requests'
'requests',
'google-api-python-client'
]

[build-system]
Expand Down
3 changes: 3 additions & 0 deletions src/goldminer/automations/a1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@

from goldminer.tasks.tistory import write_tistory_post
write_tistory_post("국내증시 " + today, content)

from goldminer.tasks.blogger import create_blogger_post
create_blogger_post("국내 증시 " + today, content)
37 changes: 37 additions & 0 deletions src/goldminer/tasks/blogger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

# 구글 클라우드 콘솔에서 받은 자격 증명 파일 경로
CLIENT_SECRETS_FILE = 'credentials.json'

# Blogger API 서비스 이름
API_SERVICE_NAME = 'blogger'
API_VERSION = 'v3'

# 인증 범위
SCOPES = ['https://www.googleapis.com/auth/blogger']

blog_id = os.environ.get("BLOGSPOT_ID")

def create_blogger_post(title, content):
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
credentials = flow.run_local_server(port=0)

service = build(API_SERVICE_NAME, API_VERSION, credentials=credentials)

blog_id = blog_id # 포스트를 게시할 블로그 ID
body = {
'kind': 'blogger#post',
'title': title,
'content': content,
}

posts = service.posts()
request = posts.insert(blogId=blog_id, body=body)
response = request.execute()
print('포스트가 성공적으로 생성되었습니다. 포스트 ID: %s' % response['id'])

if __name__ == '__main__':
create_blogger_post('새로운 포스트 제목', '새로운 포스트 내용')

0 comments on commit da99a08

Please sign in to comment.